Idris REPL: creating a function

How do I write a function in the Idris REPL? If I enter a function definition longer: string -> string -> string

in the REPL, I get the following error message:

(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>
      ^

      

+3


source to share


1 answer


The Idris documentation has an example of what you need. You must use the command :let

. Like this:

Idris> :let longer : String -> String -> String; longer s1 s2 = if length s1 > length s2 then s1 else s2
Idris> longer "abacaba" "abracadabra"
"abracadabra" : String

      



By default the Idris REPL doesn't do anything smart, it doesn't introduce some smart multi-line mode when entering a function type. The command is :let

used to define top level bindings within the REPL.

One more point: if you want to use a string type, you must use String

(start with an uppercase letter) instead String

.

+6


source







All Articles