Friday 29 April 2016

Haskell: GHCi: it: Special variable stores the result of an expression


Whenever an expression is evaluated at GHCi prompt, GHCi implicitly binds the value to the variable 'it'.
Prelude> 1 + 2 * 3
7
Prelude> it
7
Prelude> 
Prelude> "Hello" ++ "World"
"HelloWorld"
Prelude> it
"HelloWorld"
Prelude>


If the evaluation of expression fails, then GHCi don't change the value of the variable 'it'.
Prelude> 1+ 2*3
7
Prelude> it
7
Prelude> 
Prelude> 10/-0

<interactive>:36:3:
    Not in scope: /-
    Perhaps you meant one of these:
      - (imported from Prelude), / (imported from Prelude),
      /= (imported from Prelude)
Prelude> 
Prelude> it
7



Previous                                                 Next                                                 Home

No comments:

Post a Comment