Created
July 31, 2018 08:12
-
-
Save Rydgel/42233df1c1a9199fc754144cceee780a to your computer and use it in GitHub Desktop.
Applicative OptionalT
This file contains 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
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