Skip to content

Instantly share code, notes, and snippets.

@Rydgel
Created July 31, 2018 08:12
Show Gist options
  • Save Rydgel/42233df1c1a9199fc754144cceee780a to your computer and use it in GitHub Desktop.
Save Rydgel/42233df1c1a9199fc754144cceee780a to your computer and use it in GitHub Desktop.
Applicative OptionalT
instance Monad f => Applicative (OptionalT f) where
pure ::
a
-> OptionalT f a
pure =
OptionalT . return . pure
(<*>) ::
OptionalT f (a -> b)
-> OptionalT f a
-> OptionalT f b
(OptionalT mf) <*> (OptionalT ma) =
OptionalT $ do
optf <- mf
case optf of
Empty -> return Empty
Full f -> do
opta <- ma
case opta of
Empty -> return Empty
Full a -> return $ Full (f a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment