Skip to content

Instantly share code, notes, and snippets.

@mclark1129
Last active June 30, 2017 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mclark1129/e75ee3c23749e8c216501ea8291b7998 to your computer and use it in GitHub Desktop.
Save mclark1129/e75ee3c23749e8c216501ea8291b7998 to your computer and use it in GitHub Desktop.
module Transformer where
import Control.Monad.Reader
import Control.Monad.Trans
data Config = Config { filename :: String } deriving (Show)
c = Config { filename = "a.txt" }
loadFile :: ReaderT Config IO String
loadFile = do
fname <- asks filename
liftIO $ readFile fname
@bitemyapp
Copy link

module ReaderMClark where

import Control.Monad.Reader
import Control.Monad.Trans

data Config = Config { filename :: String } deriving (Show)

c = Config { filename = "a.txt" }

loadFile :: ReaderT Config IO String
loadFile = do
     -- This is how I assume I get the filename from the config
     -- fname <- ask filename
     fname <- asks filename
     -- can use let bindings to assert a type and see what it is
     let f :: IO String
         f = fname
     -- How am I supposed to provide the fname to loadFile so that I can end up with a ReaderT Config IO String?
     return loadFile fname

@mclark1129
Copy link
Author

Updated with the correct solution. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment