Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data Ex a b = Exc a | Normal b
- instance (Show a, Show b)=>Show (Ex a b) where
- show (Normal a) = show a
- show (Exc b) = show b
- instance (Eq a, Eq b)=>Eq (Ex a b) where
- Normal x == Normal y = x == y
- Exc x == Exc y = x == y
- _ == _ = False
- instance Functor (Ex e) where
- fmap f (Normal a) = Normal (f a)
- fmap f (Exc a) = Exc a
- instance Applicative (Ex e) where
- pure = Normal
- (Exc x) <*> _ = Exc x
- _ <*> (Exc x) = Exc x
- (Normal f) <*> (Normal b) = Normal (f b)
- instance Monad (Ex e) where
- return = Normal
- (Exc x) >>= func = Exc x
- (Normal x) >>= func = func x
- _ >> x = x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement