[Haskell-cafe] GHCi shows result of (IO a) only if (a) is in class Show

Sumit Sahrawat, Maths & Computing, IIT (BHU) sumit.sahrawat.apm13 at iitbhu.ac.in
Sun Apr 26 04:26:11 UTC 2015


On 26 April 2015 at 06:10, Alexey Vagarenko <vagarenko at gmail.com> wrote:

> Yes, but ghci shows an error if it can't print a value, except when the
> value is in IO monad. Compare:
> Prelude> id
> <interactive>:6:1:
>     No instance for (Show (a0 -> a0))
>       (maybe you haven't applied enough arguments to a function?)
>       arising from a use of `print'
>     In a stmt of an interactive GHCi command: print it
> Prelude>
>
> and
>
> Prelude> return id
> Prelude>
>

 This behavior is necessary. For example, if we used any function with
result of type IO (), such as writeFile, we don't want an error as we are
interested in the side-effects only.


>
> воскресенье, 26 апреля 2015 г., 5:48:55 UTC+6 пользователь Sumit Sahrawat,
> Maths & Computing, IIT (BHU) написал:
>>
>> If something can't be shown (converted to a string), then it can't be
>> printed (as a string).
>>
>> On 25 April 2015 at 17:51, Daniel van den Eijkel <dv... at gmx.net> wrote:
>>
>>> I wrote a parser and it took me a while to realize why GHCi suddenly did
>>> not show any result nor an error message anymore.
>>>
>>> My parsing function has type (IO Expression), Expression is in class
>>> Show.
>>>
>>> After changing the parser to (IO Declaration), it did not show anything
>>> anymore, because Declaration was not in class Show.
>>>
>>> When I typed (parseFile "input.txt" >>= print), I got the error message
>>> and understood what was going on. But for I while I was really confused
>>> what's happening.
>>>
>>> Just wanted to share this.
>>>
>>> Best,
>>> Daniel
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskel... at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>>
>>
>>
>>
>> --
>> Regards
>>
>> Sumit Sahrawat
>>
>


-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150426/103a6dea/attachment.html>


More information about the Haskell-Cafe mailing list