That's not your actual code – that code does not produce those messages.
Your actual code looks more like this:
fun inclist ([], 0) = []
| inclist (l, inc) = map (fn x => x + inc) l;
inclist [1,2,3,4,5] 1;
with definition clauses of the same shape.
You have defined a function that takes a pair of an int list
and an int
and returns an int list
.
As the error message says: int list * int -> int list
.
Then you try to apply this function to something that is not such a pair.
inclist [1,2,3,4,5] 1
is the same as (inclist [1,2,3,4,5]) 1
- it first applies inclist
to [1,2,3,4,5]
, and then applies the result - which must be a function - to 1
.
Your first message refers to inclist [1,2,3,4,5]
, and says that [1,2,3,4,5]
is not an int list * int
, which inclist
needs.
The second message refers to your applying inclist [1,2,3,4,5]
to 1
, when inclist [1,2,3,4,5]
is not a function.
(It is slightly peculiar that polyml claims that inclist [1,2,3,4,5]
is an int list
, when it has a type error according to the previous message. One possible explanation is that polyml doesn't bother to check the type of the argument but goes "inclist
applied to whatever argument is an int list
".)
The solution is to either pass a pair like the function expects:
inclist ([1,2,3,4,5], 1)
or to define the function in the "curried" manner:
fun inclist [] 0 = []
| inclist l inc = map (fn x => x + inc) l;
inclist [1,2,3,4,5] 1;
On a side note, that first special case is unnecessary.
If you're worried about inefficiency, it makes more sense to special-case 0
than []
(avoiding zero-additions in a huge list can be beneficial; only avoiding it with the empty list is pointless).
fun inclist (l, 0) = l
| inclist (l, inc) = map (fn x => x + inc) l;
but this will also do the job:
fun inclist (l, inc) = map (fn x => x + inc) l;