RE: [Haskell-cafe] How can I stop GHCi from calling show for IOactions?

2007-09-21 Thread Simon Peyton-Jones
| 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)

I've added Ryan's comments to
http://hackage.haskell.org/trac/ghc/ticket/1721

Others might want to add further suggestions there.

Simon

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


RE: [Haskell-cafe] How can I stop GHCi from calling show for IOactions?

2007-09-20 Thread Simon Peyton-Jones
| | It seems that GHCi outputs the contents of the variable you've created
| | when there's only one of them.
| 
| Indeed, that is documented behaviour (first bullet here:
| 
http://www.haskell.org/ghc/docs/latest/html/users_guide/ch03s04.html#ghci-stmts
| )
| Perhaps it's confusing behaviour?  If so do suggest an alternative.
|
| why not simply do what the flag suggests, either always try to
| print the bind-result, or never? i assume there has been a use
| case where this special case has been found useful/necessary?

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'll add a Trac feature request so as not to forget this suggestion.

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


Re: [Haskell-cafe] How can I stop GHCi from calling show for IOactions?

2007-09-20 Thread Ryan Ingram
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


Re: [Haskell-cafe] How can I stop GHCi from calling show for IOactions?

2007-09-20 Thread Dougal Stanton
On 20/09/2007, Ryan Ingram [EMAIL PROTECTED] wrote:

 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 agree with this interpretation. If I want to just *do* the action,
I'll type it. If I want to *store* the action then I'll bind it to
something. That's the intuition I have, anyway. And it works for pure
functions:

Prelude let ns = [1..]
Prelude [1..]

The difference between those two feels like the difference between:

Prelude contents - readFile massive.txt
Prelude readFile massive.txt

But as Ryan mentioned, this may just be poor intuition from an overly
imperative mindset...

Cheers,

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


Re: [Haskell-cafe] How can I stop GHCi from calling show for IOactions?

2007-09-18 Thread Claus Reinke

| It seems that GHCi outputs the contents of the variable you've created
| when there's only one of them.

Indeed, that is documented behaviour (first bullet here:
http://www.haskell.org/ghc/docs/latest/html/users_guide/ch03s04.html#ghci-stmts
)
Perhaps it's confusing behaviour?  If so do suggest an alternative.


why not simply do what the flag suggests, either always try to
print the bind-result, or never? i assume there has been a use
case where this special case has been found useful/necessary?

as for earlier questions/suggestions in this thread:


 Is there a way to make GHCi not print the result
of an action but still make my variables get bound?


This seems to be a common question (I myself asked it recently), so
I've added an entry to the GHCi page on the wiki.

Ideally, it would be nice if this were discoverable from within GHCi,
but I'm not sure how this would best be done.


i've run into this myself!-) there is a patch pending for ghc head 
(so it may not be in 6.8.1:-( that would show the GHCi-specific 
flags together with the GHCi options:


   Prelude :set
   options currently set: none.
   GHCi-specific dynamic flag settings:
 -fno-print-explicit-foralls
 -fprint-bind-result
 -fno-break-on-exception
 -fno-break-on-error
 -fno-print-evld-with-show
   other dynamic, non-language, flag settings:
   ..

so you'd at least know which possibly relevant flags there
are, and if the names are not expressive enough, the :help would
point you to the flag reference:

   :help
   ..
 Options for ':set' and ':unset':
   
   +rrevert top-level expressions after each evaluation

   +sprint timing/memory stats after each evaluation
   +tprint type after evaluation
   -flags  most GHC command line flags can also be set here
(eg. -v2, -fglasgow-exts, etc.)
   for GHCi-specific flags, see User's Guide,
   Flag reference, Interactive-mode options
   ..


I've always wondered if ghc(i) --help should be a bit more
instructive, or perhaps if there were a man page that lay somewhere
between the --help message and the manual in terms of
comprehensiveness. It's a pretty major jump from a short description
of 4 command line options (only one of which I have ever used) to the
entire manual, with a ~10 page table of contents.


please note that the flag reference, which was pointed to 
earlier in this thread, is just such a summary, and there's

a subsection dedicated to GHCi-specific options. there
isn't much in that section in 6.6.1:

http://www.haskell.org/ghc/docs/latest/html/users_guide/flag-reference.html#id3132588

but in ghc head and the upcoming 6.8, you'll find most of 
the GHCi-related flags summarized there.


hth,
claus

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