Score in GHCi 7.8.3

Now I am reading a book for parallel programming in Haskell. And here I see an example:

Prelude> let x = 2 + 3
Prelude> :sp x
x = _
Prelude> x
5
Prelude> :sp x
x = 5

But instead, in my GHCi 7.8.3 from the Haskell platform 2014.02, I got this behavior:

Prelude> let x = 2 + 3
Prelude> :sp x
x = _
Prelude> x
5
Prelude> :sp x
x = _

See the last line. Why is x not evaluated? I tried using "seq x ()" and it is not evaluated either.

+4
source share
1 answer

Creating a type of monomorphism xallowed to solve the problem.

Prelude> let x::Int ; x = 2+3
Prelude> :sp x
x = _
Prelude> x
5
Prelude> :sp x
x = 5

The problem here is that it 2+3can be any numeric type, so xit looks more like a hidden function.

GHCi . , , , " ". , GHCi .

+4

Source: https://habr.com/ru/post/1569114/


All Articles