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

32 views
Skip to first unread message

Daniel van den Eijkel

unread,
Apr 25, 2015, 8:21:37 AM4/25/15
to Haskell Cafe
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...@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Sumit Sahrawat, Maths & Computing, IIT (BHU)

unread,
Apr 25, 2015, 7:48:55 PM4/25/15
to Daniel van den Eijkel, Haskell Cafe
If something can't be shown (converted to a string), then it can't be printed (as a string).
--
Regards

Sumit Sahrawat

Alexey Vagarenko

unread,
Apr 25, 2015, 8:40:33 PM4/25/15
to haskel...@googlegroups.com, haskel...@haskell.org, sumit.sahr...@iitbhu.ac.in, dv...@gmx.net
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>



воскресенье, 26 апреля 2015 г., 5:48:55 UTC+6 пользователь Sumit Sahrawat, Maths & Computing, IIT (BHU) написал:

Sumit Sahrawat, Maths & Computing, IIT (BHU)

unread,
Apr 25, 2015, 10:44:59 PM4/25/15
to Alexey Vagarenko, Haskell-cafe Cafe, haskel...@googlegroups.com
On 26 April 2015 at 06:10, Alexey Vagarenko <vaga...@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...@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...@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe



--
Regards

Sumit Sahrawat



--
Regards

Sumit Sahrawat

Sumit Sahrawat, Maths & Computing, IIT (BHU)

unread,
Apr 26, 2015, 12:26:22 AM4/26/15
to Alexey Vagarenko, Haskell-cafe Cafe, haskel...@googlegroups.com
On 26 April 2015 at 06:10, Alexey Vagarenko <vaga...@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...@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...@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe



--
Regards

Sumit Sahrawat



--
Regards

Sumit Sahrawat

Sumit Sahrawat, Maths & Computing, IIT (BHU)

unread,
Apr 26, 2015, 12:30:58 AM4/26/15
to Alexey Vagarenko, Haskell-cafe Cafe, haskel...@googlegroups.com
Sorry for double posting, the highlighted code example seems to be a problem for mailer...@google.com.

--
Regards

Sumit Sahrawat
Reply all
Reply to author
Forward
0 new messages