Skip to content

Instantly share code, notes, and snippets.

@songpp
Created April 2, 2011 07:46
Show Gist options
  • Save songpp/899315 to your computer and use it in GitHub Desktop.
Save songpp/899315 to your computer and use it in GitHub Desktop.
haskell very simple tree
module Tree where
data Tree v = EmptyTree
| Node v (Tree v) (Tree v)
deriving Show
singleton value = Node value EmptyTree EmptyTree
--map f EmptyTree = EmptyTree
--map f Node v left right = Node (f v) (map f left) (map f right)
instance Functor Tree where
fmap f EmptyTree = EmptyTree
fmap f (Node v left right) = Node (f v) (fmap f left) (fmap f right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment