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

I am experimenting in GHCi and I have a moderately long job (5 minutes) that I am trying to set up. The result starts to print partially, and I can often say that my algorithm is not configured correctly after 1 minute or less, so I cancel the operation. But when I find the result, I want to allow it to continue to the end, and then use it later. If I assign it when I started it, I do not see it in the process of processing it. Is there a way to access the result of the previous expression introduced in GHCi?

+8
haskell ghci
source share
1 answer

For this purpose, GHCi has a special variable called it .

 Prelude> 1 1 Prelude> it 1 

The reason for this, as explained in the GHCi docs , is that expressions other than IO behave like this:

 someExpr ==> let it = someExpr print it 

If someExpr was IO, then we would have

 it <- someExpr print it 

therefore, it should always be the result of your previous expression.

+16
source share

All Articles