Skip to content

Instantly share code, notes, and snippets.

@jstimpfle
Created June 28, 2016 13:52
Show Gist options
  • Save jstimpfle/a08b0f62e4c5583e88be260be10b0939 to your computer and use it in GitHub Desktop.
Save jstimpfle/a08b0f62e4c5583e88be260be10b0939 to your computer and use it in GitHub Desktop.
-- 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