Skip to content

Instantly share code, notes, and snippets.

@paulp
Created August 23, 2018 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulp/c0740d7a4fa79dfc145d2984981c7d61 to your computer and use it in GitHub Desktop.
Save paulp/c0740d7a4fa79dfc145d2984981c7d61 to your computer and use it in GitHub Desktop.
instance Monad f => Applicative (OptionalT f) where
pure = OptionalT . pure . Full
mf <*> ma = OptionalT $ do
optf <- runOptionalT mf
case optf of
Empty -> return Empty
Full f -> do
opta <- runOptionalT ma
return $ f <$> opta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment