Idris REPL:创建功能

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)

She*_*rsh 7

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.

  • @Moebius不,目前还没有这样的方式.不幸的是,伊德里斯是非常年轻的语言,生态系统很差.没有付出太多努力.你想要的是一个未解决的问题:https://github.com/idris-lang/Idris-dev/issues/1747 (2认同)