GHCi中的函数定义

时间:2014-12-16 09:01:52

标签: haskell ghci

是否可以在 GHCi 中编写带有type-signature的多行函数定义(就像在源文件中写一样)?

我到目前为止尝试过这样的事情:

Prelude> :{
Prelude| let f :: Int -> Int;
Prelude| f i = i + 1
Prelude| :}

<interactive>:9:1: parse error on input ‘f’

但它没有用......我还有什么可以尝试的吗?

1 个答案:

答案 0 :(得分:4)

注意缩进:

Prelude> :{
Prelude| let f :: Int -> Int
Prelude|     f i = i + 1
Prelude| :}
Prelude> :t f
f :: Int -> Int
Prelude> f 1
2