gpt4 book ai didi

read-eval-print-loop - idris REPL : creating function

转载 作者:行者123 更新时间:2023-12-04 08:21:56 25 4
gpt4 key购买 nike

如何在 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>
^

最佳答案

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 中的任何顶级绑定(bind)。

另一个时刻:如果你想使用字符串类型,你应该使用 String (以大写字母开头)而不是 string .

关于read-eval-print-loop - idris REPL : creating function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45054824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com