Skip to content

Instantly share code, notes, and snippets.

@5outh
Created December 27, 2012 21:02
Show Gist options
  • Save 5outh/4391950 to your computer and use it in GitHub Desktop.
Save 5outh/4391950 to your computer and use it in GitHub Desktop.
instance Functor Tree where
fmap f (Leaf a) = Leaf $ f a
fmap f (Node a b) = Node (f a) (map (fmap f) b)
instance Comonad Tree where
coreturn (Leaf a) = a
coreturn (Node a _) = a
cojoin l@(Leaf a) = Leaf l
cojoin n@(Node a b) = Node n (map cojoin b)
x =>> f = fmap f $ cojoin x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment