I am currently just starting out with OCaml and am working through this tutorial:
Inside the utop REPL,
We’ve defined a recursive function range
that takes two int lo
and hi
and returns a list from lo
to hi
let rec range lo hi =
if lo > hi then
[]
else
lo :: range (lo + 1) hi;;
Later, in the same REPL session we define another function sum
that uses pattern matching to take a list (of ints) and return the sum:
let rec sum u =
match u with
| [] -> 0
| x :: v -> x + sum v;;
So, I naively think, why not take the range function, give it two ints to generate a list then pass that list straight into sum
?
sum range 1 10;;
Error: The function 'sum' has type int list -> int
It is applied to too many arguments
Line 1, characters 10-11:
This extra argument is not expected.
I feel like it’s probably some syntactic thing that’s missing since, I believe anyway, the types of the inputs and outputs should match up - but I’m quite open to being shown where I’m wrong.
Thanks in advance.