On 9/20/07, Simon Peyton-Jones <[EMAIL PROTECTED]> wrote:
> Hmm.  Currently GHCi prints the value of the *variable* that you bind.  For 
> example
>
>        Just x <- foo 4
>
> will print the value of x, *not* the value of (Just x).  So if two variables 
> are bound, there'd be two values to print.
>
> But an alternative behaviour would be to print the value of the LHS, 
> constructors and all. That is in the above example, print
>        Just <value of x>
> Then if there were two values, for example
>        (x,Just y) <- bar 5
> then it'd print
>        ( <value of x>, Just <value of y> )
>
> That would be a change from current behaviour, but it'd look identical when 
> the LHS was a simple variable (the wildly common case), and it'd do something 
> useful when multiple variables are bound.

I think a more consistent behavior would be to not print the LHS at
all.  If you wanted to print the result of the computation you could
just do:

    Prelude> bar 5

or, if you also wanted bound variables afterwards:

    Prelude> (x, Just y) <- bar 5
    Prelude> (x, Just y)

Perhaps this is my imperative background speaking, but I don't see
much difference at the GHCi prompt between these two:

    Prelude> let x = 5
    Prelude> x <- return 5

I think they should have the same behavior by default; otherwise it's
just confusing to the new user.

For reference, I ran into this problem while playing around on the
ICFP contest problem, and I became quite frustrated trying to do
    dna <- Data.ByteString.Char8.readFile "endo.dna"
and having to wait a few minutes for the console to catch up while
using GHCi as a simple interactive debugger.

The best argument I can think of for changing the default value of
that option is this:

The workaround for printing the value of bound variables, if the
default is to not print and you don't know the options, is simple:
just type the bound variable in as an expression afterwards.

On the other hand, there is no workaround to not print the value of
bound variables, if you don't know about the existence of that option.
 In my case, I did do a cursory look to find an option to change this
behavior, but I missed it in the documentation.

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

Reply via email to