factorial :: Integer -> Integer
factorial n = product [1..n]
Run Code Online (Sandbox Code Playgroud)
以下是好的:
let factorial n = product [1..n]
Run Code Online (Sandbox Code Playgroud)
我没有看到如何在交互式shell中添加类型声明.
如果您想自己指定类型签名,可以使用分号在ghci中执行此操作,即:
let factorial :: Integer -> Integer; factorial n = product [1..n]
Run Code Online (Sandbox Code Playgroud)
在此处说明的多行设置旁边,如果您不想编写分号,则可以使用此设置.
?> :{
?> | let factorial :: Integer -> Integer
?> | factorial n = product [1..n]
?> :}
?> :t factorial
factorial :: Integer -> Integer
Run Code Online (Sandbox Code Playgroud)