0

In the tutorial What I Wish I Knew When Learning Haskell there is this interaction inside GHCi regarding the use of the :sprint command to inspect the state of evaluation of some variable:

λ: let a = [1..] :: [Integer]
λ: :sprint a
a = _
λ: a !! 4
5
λ: :sprint a
a = 1 : 2 : 3 : 4 : 5 : _ 

However, if we ommit the part :: [Integer] from the definition of a, the last call to :sprint a will return a = _ and not a = 1 : 2 : 3 : 4 : 5 : _.

Why?

ANSWER: the monomorphism restriction must be turned on/off inside GHCi via :set -XMonomorphismRestriction and :set -XNoMonomorphismRestriction (see Reid Barton's comment below). And the best explanation I found for :sprint behavior is here.

mljrg
  • 4,430
  • 2
  • 36
  • 49
  • 1
    If you are using 7.10.2 then the monomorphism restriction is turned off by default, so the type of `[1..]` (without `:: Integer`) is polymorphic and thus the referred to answer applies. – ErikR Sep 08 '15 at 16:11
  • @user5402 I am using GHCi 7.8.3, and even if I launch it with `ghci -XNoMonomorphismRestriction` or `ghci -XMonomorphismRestriction` I still have the same problem. I suppose that `:sprint` should have been implemented to make this subtlety transparent for the user. – mljrg Sep 08 '15 at 17:05
  • 3
    Apparently `ghci -XMonomorphismRestriction` doesn't turn on the monomorphism restriction. You need to `:set -XMonomorphismRestriction` from inside ghci. Confusing... – Reid Barton Sep 08 '15 at 17:57
  • @ReidBarton Thanks, it worked. I don't understand why this monomorphism restriction is still around generating lots of confusion. Anyway, with or without such restriction, the problem is that GHCi has inconsistencies regarding `:sprint` (see [here](https://www.reddit.com/r/haskell/comments/3dznm2/question_about_the_behavoir_of_sprint_in_ghci/)). – mljrg Sep 08 '15 at 18:42

0 Answers0