[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 02:44:51 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
> 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> return id
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
>>> 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.
>>> Haskell-Cafe mailing list
>>> Haskel... at haskell.org
>> Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe