0

I want to be able to write

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

using the Eff Monad

Is this possible to do using Eff?

If not how can we make it work not using Eff?

user47376
  • 2,263
  • 3
  • 21
  • 26

1 Answers1

1

You can use the MaybeT and ReaderT monad transformers on top of Eff, but you cannot match the two in the way you wrote above:

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)
Phil Freeman
  • 4,199
  • 1
  • 20
  • 15
  • I don't like monad transformers, Iv'e seen some talks where something like Purescript's Eff monad was used with monads like Reader, but I don't know if it's possible to do in Purescript, maybe we need to define a new monad similar to Eff. – user47376 Apr 12 '17 at 21:30