Your title asks how to concatenate lists, but your question seems rather different.
To concatenate lists, you can use the @
operator. In many cases, code that depends on this operator is slower than it needs to be (something to keep in mind for later :-).
Here are some things I see wrong with the code you give:
a. You can't name a function function
, because function
is a keyword in OCaml.
b. If you use the @
operator, you should have lists on both sides of it. As near as I can see, the thing on the left in your code is not a list.
c. Function calls have higher precedence than infix operators. So myfun n - 2
is parsed as (myfun n) - 2
. You probably want something closer to myfun (n - 2)
.
Even with these changes, your code seems to generate a list of integers that are 2 apart, which isn't what you say you want. However, I can't understand what the function is actually supposed to return.