[Haskell-cafe] Binding of an integer variable

Daniel Fischer daniel.is.fischer at googlemail.com
Thu Jul 28 21:06:25 CEST 2011


On Thursday 28 July 2011, 20:43:30, Paul Reiners wrote:
> I have a question about the following GHCi interaction:
> 
> Prelude> let x = 23
> Prelude> :show bindings
> x :: Integer = _
> 
> What is the meaning of the underscore in the third line?  Why doesn't it
> say this, instead?
> 
> x :: Integer = 23

Because x is not yet evaluated:

Prelude> let x = 23
Prelude> :show bindings
x :: Integer = _
Prelude> x
23
Prelude> :show bindings
it :: Integer = 23
x :: Integer = 23

When bindings are shown, no evaluation takes place, things are only shown 
as far as they are evaluated, unevaluated parts are represented by an 
underscore, (partially) evaluated parts that aren't shown are represented 
by an ellipsis:

Prelude> let xs = [1 .. 100]
Prelude> :show bindings
xs :: [Integer] = _
Prelude> head xs
1
Prelude> :show bindings
it :: Integer = 1
xs :: [Integer] = 1 : _
Prelude> xs !! 3
4
Prelude> :show bindings
it :: Integer = 4
xs :: [Integer] = 1 : 2 : 3 : 4 : _
Prelude> last xs
100
Prelude> :show bindings
it :: Integer = 100
xs :: [Integer] = 1 : 2 : 3 : 4 : 5 : ....



More information about the Haskell-Cafe mailing list