Created
June 28, 2016 13:52
-
-
Save jstimpfle/a08b0f62e4c5583e88be260be10b0939 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Applicative instance where we have NOT (ap = (<*>)) | |
-- is this valid? | |
data ParFallible e a = Fail e | Success a | |
instance Functor (ParFallible e) where | |
fmap _ (Fail e) = Fail e | |
fmap f (Success a) = Succes (f a) | |
instance Monoid e => Applicative (ParFallible e) where | |
pure = Success | |
Fail e <*> Fail e' = Fail (e <> e') | |
Fail e <*> Success _ = Fail e | |
Success _ <*> Fail e = Fail e | |
Success f <*> Success a = Success (f a) | |
instance Monoid e => Monad (ParFallible e) where | |
return = Success | |
Fail e >>= _ = Fail e | |
Success a >>= f = f a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment