Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. data Tree a = Nil | Branch (Tree a) a (Tree a) deriving (Eq, Show)
  2.  
  3. instance Functor Tree where
  4. fmap _ Nil = Nil
  5. fmap f (Branch l x r) = Branch (fmap f l) (f x) (fmap f r)
  6.  
  7. instance Applicative Tree where
  8. pure f = Branch (pure f) f (pure f)
  9. (<*>) Nil _ = Nil
  10. (<*>) _ Nil = Nil
  11. (<*>) (Branch fl fx fr) (Branch l x r) = Branch (fl <*> l) (fx x) (fr <*> r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement