我希望能够写
x :: Eff (reader :: Reader Int, maybe :: Maybe) Int
x = do
config <- ask -- configuration from (Reader Int) monad
just config -- using (Maybe) Monad
runX :: Int
runX = runPure (runMaybe doIfNothing (runReader 6 x)) -- outputs: 6
使用Eff
Monad
这可以使用Eff
吗?
如果不是,我们怎样才能让它无法使用Eff
?
答案 0 :(得分:1)
您可以在MaybeT
之上使用ReaderT
和Eff
monad变换器,但是您无法按照上面所写的方式匹配这两者:
import Prelude
import Data.Maybe
import Control.Monad.Eff
import Control.Monad.Eff.Class
import Control.Monad.Eff.Console
import Control.Monad.Maybe.Trans
import Control.Monad.Reader.Trans
x :: ReaderT Int (MaybeT (Eff (console :: CONSOLE))) Int
x = do
liftEff (log "Asking...")
config <- ask
pure config
main :: Eff (console :: CONSOLE) (Maybe Int)
main = runMaybeT (runReaderT x 6)