Marco Faustinelli
Marco Faustinelli

Reputation: 4226

How do I run this method with MonadReader and MonadIO?

I am following this post about the reader monad in Haskell.

It starts with the definition:

load :: Config -> String -> IO String
load config x -> readFile (config ++ x)

Where Config is a type alias for String and it represents a directory name.

The method is meant to display on screen the content of a file, for example "./myFile.txt".

I run this method from ghci with:

load "./" "myFile.txt"

The second example introduces the reader monad:

load :: (MonadReader Config m, MonadIO m) => String -> m String
load x = do
    config <- ask
    liftIO $ readFile (config ++ x)

Question is: how do I run it from ghci?

I have tried with things like:

(runReader load "myFile.txt") "./"

but no joy.

What is the command that loads ./myFile.txt?

Upvotes: 1

Views: 297

Answers (1)

Daniel Wagner
Daniel Wagner

Reputation: 153247

runReaderT (load "myFile.txt") "./" :: IO String

Upvotes: 3

Related Questions