Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| // | |
| // On MacOSX compile with: | |
| // g++ -framework OpenGL -framework GLUT -o example example.cpp | |
| // | |
| #include <stdlib.h> | |
| #include <GLUT/glut.h> | |
| GLuint program; |
| import Data.Traversable | |
| import Control.Monad.Free | |
| import Control.Comonad | |
| import Control.Comonad.Trans.Store | |
| type Zipper t a = Free (Store a) (t a) | |
| zipper :: Traversable t => t a -> Zipper t a | |
| zipper = traverse (wrap . store return) |
| module Split where | |
| open import Data.Bool | |
| open import Data.Nat | |
| open import Data.Nat.Properties | |
| open import Data.List hiding ([_]) | |
| open import Data.Product | |
| open import Relation.Binary | |
| open import Relation.Binary.PropositionalEquality |
| ;; As part of the implementation of Virtua's [1] object system I need | |
| ;; a facility called DEFINE-CONSTRUCTOR that defines a convenient | |
| ;; function for creating an instance of a class and setting its slots. | |
| (define-constructor make-person Person (firstname lastname)) | |
| ;; should be operationally equivalent to | |
| (define make-person | |
| (lambda (firstname lastname) |
| import Control.Monad.Free | |
| import Data.Functor.Compose | |
| import Data.Traversable | |
| type Diss p c j = c -> Free (Compose ((,) j) ((->) c)) (p c) | |
| right :: Traversable p => Either (p j) (Diss p c j, c) -> Either (j, Diss p c j) (p c) | |
| right e = case either (traverse (\j -> Free (Compose (j, Pure)))) (uncurry ($)) e of | |
| Free (Compose jd) -> Left jd | |
| Pure pc -> Right pc |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| var parser = document.createElement('a'); | |
| parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
| parser.protocol; // => "http:" | |
| parser.hostname; // => "example.com" | |
| parser.port; // => "3000" | |
| parser.pathname; // => "/pathname/" | |
| parser.search; // => "?search=test" | |
| parser.hash; // => "#hash" | |
| parser.host; // => "example.com:3000" |
| module Types where | |
| open import Level | |
| open import Function | |
| open import Algebra | |
| open import Data.Empty | |
| open import Data.Unit | |
| open import Data.Sum as Sum | |
| open import Data.Product as Prod | |
| open import Relation.Binary |