Created
April 2, 2011 07:46
-
-
Save songpp/899315 to your computer and use it in GitHub Desktop.
haskell very simple tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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