Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
PureScript モナド変換子 MaybeT 例
module MaybeTExample
( main
) where
import Control.Monad.Maybe.Trans (MaybeT(..), lift, runMaybeT)
import Data.Maybe (Maybe(..))
import Effect (Effect)
import Effect.Class.Console (log)
import Prelude (Unit, discard, map, pure, unit, void)
-- newtype MaybeT m a = MaybeT (m (Maybe a))
-- runMaybeT :: ∀ m a. MaybeT m a → m (Maybe a)
main :: Effect Unit
main =
expr1 :: Unit
expr1 = unit
expr1' :: MaybeT Effect Unit
expr1' = pure expr1
expr2 :: Maybe Unit
expr2 = Just unit
expr2' :: MaybeT Effect Unit
expr2' = MaybeT (pure expr2)
expr3 :: Effect Unit
expr3 = log "expr3"
expr3' :: MaybeT Effect Unit
expr3' = lift expr3 -- or MaybeT (map Just expr3)
expr4 :: Effect (Maybe Unit)
expr4 = map Just (log "expr4")
expr4' :: MaybeT Effect Unit
expr4' = MaybeT expr4
block :: MaybeT Effect Unit
block = do
main' :: Effect (Maybe Unit)
main' = runMaybeT block
void main'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment