(1)
ghci stores the result of the last expression into a variable whose name is “it”. (This isn’t a Haskell language feature; it’s specific to ghci alone.)
举例如下:
> "foo"
"foo"
> it ++ "bar"
"foobar"
> it
"foobar"
(2)可以使用:set <option>
和:unset <option>
来设置和取消一些选项。以打印计算的结果类型为例:
> :set +t
> fst ('a', 'b')
'a'
it :: Char
> :unset +t
> fst ('a', 'b')
'a'
(3)在ghci
中定义变量与源文件中定义变量不一样,需要在变量前加上let
:
ghci> let a = 10
ghci> b = 100
<interactive>:9:3: parse error on input ‘=’