On 16 March 2015 at 19:51, Maurizio Vitale <mrz.vtl@gmail.com> wrote:suppose I have a restricted IO monad, RIO that only exposes readFile.and then I have a monad SIO that will eventually provide a virtual file system from a map path->content, also with a readFile function returning SIO(String).What is the way to write a function parseFile that can operate in both monads so that I can use SIO for testing? should I define a third monad CompileMonad that has instances for both RIO and SIO and then having parseFile :: CompileMonad ast?You might be able to do something like,class MonadIO m => ProvidesReadFile m wherereadFile :: FilePath -> m Stringinstance ProvidesReadFile RIO wherereadFile = readFileRIO -- the RIO specific readFileinstance ProvidesReadFile SIO wherereadFile = readFileSIO -- the SIO specific readFileparseFile :: ProvidesReadFile m => FilePath -> m astparseFile = dof <- readFilelet ast = parse f -- the pure parserreturn ast -- works for both monadsThanks,Maurizio
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
This is more suitable for the haskell-cafe. I am posting it there so that more people might comment on it.HTH.--RegardsSumit Sahrawat
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners