Re: [Haskell-cafe] Binding of an integer variable

2011-07-28 Thread Albert Y. C. Lai

Another fun example:

let c = 0 : c
let b = 1 : 1 : c
:show bindings
length (take 5 c)
:show bindings
take 3 c
:show bindings

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Binding of an integer variable

2011-07-28 Thread Henning Thielemann


On Thu, 28 Jul 2011, Brandon Allbery wrote:


On Thu, Jul 28, 2011 at 14:52, Henning Thielemann 
 wrote:
I have never used ':show bindings' before ... in other cases like
  let x='a'
and
  let x=23::Int


Since you gave explicit types, x is bound to strict values directly; it's only 
when no type is given that GHCi needs to translate
the constant per the Language Report to an invocation of fromInteger.


let x=23::Integer

is left unevaluated, too. I do not understand, how fromInteger may change 
the state of evaluation.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Binding of an integer variable

2011-07-28 Thread Daniel Fischer
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 : 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Binding of an integer variable

2011-07-28 Thread Brandon Allbery
On Thu, Jul 28, 2011 at 14:52, Henning Thielemann <
lemm...@henning-thielemann.de> wrote:

> I have never used ':show bindings' before ... in other cases like
>   let x='a'
> and
>   let x=23::Int
>

Since you gave explicit types, x is bound to strict values directly; it's
only when no type is given that GHCi needs to translate the constant per the
Language Report to an invocation of fromInteger.

-- 
brandon s allbery  allber...@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Binding of an integer variable

2011-07-28 Thread Henning Thielemann


On Thu, 28 Jul 2011, 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


I have never used ':show bindings' before ... in other cases like
   let x='a'
and
   let x=23::Int
 the value of 'x' is shown. If 'x' is bound to a function, the underscore 
is shown. Thus I assume, that ':show bindings' uses the underscore for 
types without text representation. But it seems not to use the 'Show' 
class, since in this case Integers could be shown.


The documentation does not mention the output of values, at all:
  http://www.haskell.org/ghc/docs/7.0-latest/html/users_guide/ghci-commands.html

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Binding of an integer variable

2011-07-28 Thread David McBride
It hasn't been evaluated yet.  It is just a thunk.

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



On Thu, Jul 28, 2011 at 2:43 PM, 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
>
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Binding of an integer variable

2011-07-28 Thread Brandon Allbery
On Thu, Jul 28, 2011 at 14:43, 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?
>

The underscore indicates an unevaluated thunk.  In this case it's because
numeric literals are translated into function calls (in this case (fromInteger
23); even though GHCi has already applied defaulting to the type, it still
hasn't evaluated the *value* yet, and won't until it's needed due to
laziness.  If you do something like show x then the binding will be updated
to show the actual value.

-- 
brandon s allbery  allber...@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe