Ticket #1721 (new feature request)

Opened 6 years ago

Last modified 4 months ago

Make GHCi print the entire result of an interactive 'bind' statement

Reported by: simonpj Owned by:
Priority: lowest Milestone: 7.6.2
Component: Compiler Version: 6.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Suppose

  foo :: Int -> IO (Maybe Int, Bool)

Then here's a GHCi interaction:

Prelude> foo 3
(Just 3,True)           -- Entire result printed
Prelude> (Just x, _) <- foo 3
3                       -- Value of x printed
Prelude> (Just x, y) <- foo 3
                        -- Nothing at all printed
Prelude> (_, _) <- foo 3
                        -- Nothing at all printed
Prelude> 

GHCi prints the result of a bind, p <- e, if and only if the pattern p binds exactly one variable. This is a bit odd; you get no info if it binds more than one.

A different and simpler behaviour would be to print the entire result every time. That is, all the commands above would print (Just 3, True).

I'm recording this ticket so that we remember the suggestion. I don't know for sure if it's a good one. Add comments if you have an opinion

Change History

Changed 6 years ago by simonpj

Ryan Ingram writes: 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 = factorial 100
    Prelude> x <- return (factorial 100)

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.

Changed 6 years ago by claus

my personal preference would be to do away with the special case of printing bind results completely (just as with let, one can do :show bindings and show any particular variable one might want to have evaluated). since there is an option, and i can switch it off, it doesn't bother me too much, but the printing should be all or nothing (and probably using the new :print, instead of show), not "if there is exactly one variable..".

there should also be an option that specifies whether or not the result of IO monads is shown (i recall that it can be confusing if those results are not shown, but it can be annoying that they are always shown). an option, on by default, would be nicer than having to resort to things like 'let void m = m >> return ()'.

Changed 6 years ago by igloo

  • milestone set to 6.10 branch

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple

Changed 4 years ago by igloo

  • milestone changed from 6.10 branch to 6.12 branch

Changed 3 years ago by igloo

  • milestone changed from 6.12 branch to 6.12.3

Changed 3 years ago by igloo

  • priority changed from normal to low
  • milestone changed from 6.12.3 to 6.14.1

Changed 2 years ago by igloo

  • milestone changed from 7.0.1 to 7.0.2

Changed 2 years ago by igloo

  • milestone changed from 7.0.2 to 7.2.1

Changed 20 months ago by igloo

  • milestone changed from 7.2.1 to 7.4.1

Changed 15 months ago by igloo

  • priority changed from low to lowest
  • milestone changed from 7.4.1 to 7.6.1

Changed 8 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2

Changed 4 months ago by morabbin

  • failure set to None/Unknown

Bump; where does this stand wrt modern GHCi?

Note: See TracTickets for help on using tickets.