Haskell笔记 (5)—— ghci

(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 ‘=’

 

发表评论

邮箱地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.