Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data Result a = Success a | Error String
- instance (Show a) => Show (Result a) where
- show (Success a) = show a
- show (Error string) = string
- instance (Eq a) => Eq (Result a) where
- (==) (Success a) (Success b) = (a==b)
- (==) (Error a) (Error b) = (a==b)
- (==) _ _ = False
- instance Monad Result where
- return a = Success a
- (>>=) (Success a) f = f a
- (>>=) (Error a) _ = Error a
- instance Functor Result where
- fmap = map'
- instance Applicative Result where
- pure a = Success a
- (<*>) (Success f) (Success a) = Success (f a)
- (<*>) (Error a) (Error b) = Error (a++b)
- (<*>) (Error f) _ = Error f
- (<*>) _ (Error a) = Error a
- map':: (a->b)->Result a->Result b
- map' f (Success a) = Success (f a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement