5

I understand a `seq` b as "be strict on a and compute b", so undefined `seq` True throws and Exception.

I am playing around with :sprint and tried following test in ghci:

Prelude> x = [True, undefined]
Prelude> :sprint x
x = _

Okay, because x was not computed yet

Prelude> x `seq` True
True
Prelude> :sprint x
x = _

Why x = _ at this moment? I thought that seq will evaluate x at least to _:_ (or more possibly True:_), but its value still remains completely latent. It needs somehow check whether x is not undefined, so it needs to perform kind of evaluation, but why doesn't it keep the result?

I am using GHC 8.6.3

6
  • Cannot reproduce: I get x = True : _ for the last :sprint
    – chi
    Commented Dec 22, 2018 at 18:30
  • @chi which version of ghc are you using?
    – radrow
    Commented Dec 22, 2018 at 18:39
  • GHCi version 8.4.4. Weird. Try :t x to check that x :: [Bool], as it should.
    – chi
    Commented Dec 22, 2018 at 18:40
  • 4
    I can confirm this really happens in 8.6.2. It's very strange. If you use () <$ evaluate x instead, then it behaves as expected. I suggest you file a GHC tiicket.
    – dfeuer
    Commented Dec 22, 2018 at 20:27
  • Also: the undefined is irrelevant. The same happens if you use x = [True, False].
    – dfeuer
    Commented Dec 22, 2018 at 20:30

1 Answer 1

1

Okay, I made a ticket on trac (link: https://ghc.haskell.org/trac/ghc/ticket/16089) and it seems to be a bug related to another one (https://ghc.haskell.org/trac/ghc/ticket/16096).

Problem was a result of how x = y and let x = y were treated in GHCi – the first one was interpreted as toplevel binding (with monomorphism restriction turned off by default) and the second one as let statement in do block. This issue implied some other unwanted behaviors like for example lack of shadowing warnings when -Wall was turned on. You may inspect fix for this at this thread: https://phabricator.haskell.org/D5473

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.