Given this piece of OCaml code:
let rec range a b =
if a > b then []
else a :: range (a+1) b
;;
The Repl tells me what this type is:
val range : int -> int -> int list = <fun>
Introducing it, for example:
range 0 4;;
returns a list:
- : int list = [0; 1; 2; 3; 4]
However, subject to input
range -4 2;;
Gives an error:
Characters 0-5:
range -4 1;;
^^^^^
This expression has type int -> int -> int list but is here used with type int.
What am I trying to say?
source
share