Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data Ex a b = Exc a | Normal b
  2.  
  3. instance (Show a, Show b)=>Show (Ex a b) where
  4.   show (Normal a) = show a
  5.   show (Exc b) = show b
  6.  
  7. instance (Eq a, Eq b)=>Eq (Ex a b) where
  8.   Normal x == Normal y = x == y
  9.   Exc x == Exc y = x == y
  10.   _ == _ = False
  11.  
  12. instance Functor (Ex e) where
  13.   fmap f (Normal a) = Normal (f a)
  14.   fmap f (Exc a) = Exc a
  15.  
  16. instance Applicative (Ex e) where
  17.   pure = Normal
  18.   (Exc x) <*> _ = Exc x
  19.   _ <*> (Exc x) = Exc x
  20.   (Normal f) <*> (Normal b) = Normal (f b)
  21.  
  22. instance Monad (Ex e) where
  23.   return = Normal
  24.   (Exc x) >>= func  = Exc x
  25.   (Normal x) >>= func = func x
  26.   _ >> x = x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement