<div dir="ltr">Thanks!<div>This is what I had in mind, except that I'm new too Haskell so I tried English instead of code for expressing it :-)</div><div>I'll also check the IOSpec package Paul suggested,</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 16, 2015 at 7:40 AM, Sumit Sahrawat, Maths & Computing, IIT (BHU) <span dir="ltr"><<a href="mailto:sumit.sahrawat.apm13@iitbhu.ac.in" target="_blank">sumit.sahrawat.apm13@iitbhu.ac.in</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On 16 March 2015 at 19:51, Maurizio Vitale <span dir="ltr"><<a href="mailto:mrz.vtl@gmail.com" target="_blank">mrz.vtl@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">suppose I have a restricted IO monad, RIO that only exposes readFile.<div>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).</div><div><br></div><div>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?</div></div></blockquote><div><br></div></div></div><div>You might be able to do something like,</div><div><br></div><div><font face="monospace, monospace"> class MonadIO m => ProvidesReadFile m where</font></div><div><font face="monospace, monospace"> readFile :: FilePath -> m String</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> instance ProvidesReadFile RIO where</font></div><div><font face="monospace, monospace"> readFile = readFileRIO -- the RIO specific readFile</font></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace"> instance ProvidesReadFile SIO where</font></div><div><font face="monospace, monospace"> readFile = readFileSIO -- the SIO specific readFile</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"> parseFile :: ProvidesReadFile m => FilePath -> m ast</font></div><div><font face="monospace, monospace"> parseFile = do</font></div><div><font face="monospace, monospace"> f <- readFile</font></div><div><font face="monospace, monospace"> let ast = parse f -- the pure parser</font></div><div><font face="monospace, monospace"> return ast -- works for both monads</font></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>Thanks,</div><div><br></div><div> Maurizio</div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br>This is more suitable for the haskell-cafe. I am posting it there so that more people might comment on it.<div>HTH.</div><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</font></span></div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>