Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In GHCi, can I use the result of the previous expression?

Tags:

haskell

ghci

I'm doing some experimenting in GHCi, and I have a moderately long running (5 minutes) operation that I'm trying to tune. The result starts printing out partway through, and I can often tell that my algorithm isn't correctly tuned yet after 1 minute or less, so I cancel the operation. But when I do find the result, I want to allow it continue to the end, then use it afterwards as well. If I assign it when I start it, though, I can't see it as it processes. Is there any way I can access the result of the previous expression entered into GHCi?

like image 666
Drew Avatar asked Jun 06 '13 06:06

Drew


1 Answers

GHCi has the special variable it for this purpose.

Prelude> 1
  1
Prelude> it
  1

The reason for this, as explained in the GHCi docs is that non-IO expressions behave like so

someExpr ==> let it = someExpr
             print it

If someExpr were IO then we'd have

it <- someExpr
print it

so it should always be the result of your previous expression.

like image 118
Daniel Gratzer Avatar answered Oct 21 '22 20:10

Daniel Gratzer