[Haskell-cafe] How can I stop GHCi from calling "show" for IO actions?

Simon Peyton-Jones simonpj at microsoft.com
Tue Sep 18 04:37:08 EDT 2007



| -----Original Message-----
| From: haskell-cafe-bounces at haskell.org [mailto:haskell-cafe-bounces at haskell.org] On Behalf Of Sam
| Hughes
| Sent: 16 September 2007 04:53
| To: Ryan Ingram
| Cc: haskell-cafe
| Subject: Re: [Haskell-cafe] How can I stop GHCi from calling "show" for IO actions?
|
| Ryan Ingram wrote:
| > Prelude> let inf = repeat 1
| > Prelude> inf
| > [1,1,(lots of output until I press ctrl-c),Interrupted.
| > (I expect this to happen)
| > Prelude> let x = inf
| > (no output here!)
| > Prelude> :t x
| > x :: [Integer]
| > Prelude> return inf
| > [1,1,(lots of output until I press ctrl-c),Interrupted.
| > (I also expect this to happen)
| > Prelude> y <- return inf
| > [1,1,(lots of output until I press ctrl-c),Interrupted.
| > (I do not expect this to happen here!)
| > Prelude> :t y
| >
| > <interactive>:1:0: Not in scope: 'y'
| >
| > Is this a bug?  Why does "y <- return exp" have different behavior
| > than "let y = exp"?  Is there a way to make GHCi not print the result
| > of an action but still make my variables get bound?
|
| That's weird.
|
| Prelude> (x,y) <- return $ (repeat 1, repeat 2)
| Prelude> Just x <- return $ Just (repeat 1)
| [1,1,1,...
| Prelude> (x,_) <- return $ (repeat 1, repeat 2)
| [1,1,1,...
| Prelude> Just (x,y) <- return $ Just (repeat 1, repeat 2)
| Prelude>
|
| 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.

Simon


More information about the Haskell-Cafe mailing list