Moe*_*ius 6 read-eval-print-loop idris
如何在Idris REPL中编写函数?如果我longer: string -> string -> string在REPL中键入函数定义,我收到以下错误消息:
(input):1:7: error: expected: "$",
"&&", "*", "*>", "+", "++", "-",
"->", ".", "/", "/=", "::", "<",
"<$>", "<*", "<*>", "<+>", "<<",
"<=", "<==", "<|>", "=", "==",
">", ">=", ">>", ">>=", "\\\\",
"`", "|", "||", "~=~",
ambiguous use of a left-associative operator,
ambiguous use of a non-associative operator,
ambiguous use of a right-associative operator,
end of input, function argument
longer: string -> string -> string<EOF>
^
Run Code Online (Sandbox Code Playgroud)
Idris文档提供了您需要的示例.你应该使用:let命令.像这样:
Idris> :let longer : String -> String -> String; longer s1 s2 = if length s1 > length s2 then s1 else s2
Idris> longer "abacaba" "abracadabra"
"abracadabra" : String
Run Code Online (Sandbox Code Playgroud)
默认情况下,Idris REPL不会做任何智能操作,当您输入功能类型时,它不会进入某些智能多线模式.:letcommand用于定义REPL中的任何顶级绑定.
另一个时刻:如果你想使用字符串类型,你应该使用String(以大写字母开头)而不是string.
| 归档时间: |
|
| 查看次数: |
379 次 |
| 最近记录: |