Created
April 10, 2019 05:50
-
-
Save cdepillabout/9a70d61b54f5114c94f30740c4b69e3d to your computer and use it in GitHub Desktop.
show maybet
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
{-# LANGUAGE InstanceSigs #-} | |
module MaybeT where | |
import Control.Monad.Trans | |
newtype MaybeT m a = MaybeT { unMaybeT :: m (Maybe a) } | |
instance MonadTrans MaybeT where | |
lift :: Monad m => m a -> MaybeT m a | |
lift ma = MaybeT $ fmap Just ma | |
instance Functor m => Functor (MaybeT m) where | |
fmap :: forall a b. (a -> b) -> MaybeT m a -> MaybeT m b | |
fmap a2b (MaybeT ma) = MaybeT go | |
where | |
go :: m (Maybe b) | |
go = | |
let _ = ma :: m (Maybe a) | |
in fmap inner ma | |
inner :: Maybe a -> Maybe b | |
inner maybeA = undefined | |
instance Applicative m => Applicative (MaybeT m) where | |
pure :: a -> MaybeT m a | |
pure a = MaybeT $ pure (Just a) | |
(<*>) :: forall a b. MaybeT m (a -> b) -> MaybeT m a -> MaybeT m b | |
MaybeT ma2b <*> MaybeT ma = MaybeT go | |
where | |
go :: m (Maybe b) | |
go = | |
let _ = ma2b :: m (Maybe (a -> b)) | |
_ = ma :: m (Maybe a) | |
in inner <$> ma2b <*> ma | |
inner :: Maybe (a -> b) -> Maybe a -> Maybe b | |
inner maybeA2b maybeA = undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment