[Haskell-beginners] testing IO code

Maurizio Vitale mrz.vtl at gmail.com
Mon Mar 16 16:06:01 UTC 2015


Thanks!
This is what I had in mind, except that I'm new too Haskell so I tried
English instead of code for expressing it :-)
I'll also check the IOSpec package Paul suggested,

On Mon, Mar 16, 2015 at 7:40 AM, Sumit Sahrawat, Maths & Computing, IIT
(BHU) <sumit.sahrawat.apm13 at iitbhu.ac.in> wrote:

> On 16 March 2015 at 19:51, Maurizio Vitale <mrz.vtl at 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 where
>         readFile :: FilePath -> m String
>
>     instance ProvidesReadFile RIO where
>         readFile = readFileRIO    -- the RIO specific readFile
>
>     instance ProvidesReadFile SIO where
>         readFile = readFileSIO    -- the SIO specific readFile
>
>     parseFile :: ProvidesReadFile m => FilePath -> m ast
>     parseFile = do
>         f <- readFile
>         let ast = parse f    -- the pure parser
>         return ast           -- works for both monads
>
>
>> Thanks,
>>
>>   Maurizio
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at 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.
>
> --
> Regards
>
> Sumit Sahrawat
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150316/4f16f2ef/attachment.html>


More information about the Beginners mailing list