如何在Idris REPL中编写函数?如果我在REPL中键入函数定义longer: string -> string -> string
,则会收到以下错误消息:
(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>
^
答案 0 :(得分:7)
Idris documentation有你需要的例子。您应该使用: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
默认情况下,Idris REPL不会做任何智能操作,当您输入功能类型时,它不会进入某些智能多线模式。 :let
命令用于定义REPL中的任何顶级绑定。
另一个时刻:如果你想使用字符串类型,你应该使用String
(以大写字母开头)而不是string
。