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?

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.