Here's my function:
fun inclist [] 0 = []
| inclist (l, inc) = map (fn x => x + inc) l;
l is a list of ints, and I'm trying to add inc to each integer in l.
But I'm getting these errors
Function: inclist : int list * int -> int list
Argument: [1, 2, 3, 4, 5] : int list
Reason: Can't unify int list to int list * int (Incompatible types)
Function: inclist [1, 2, 3, 4, ...] : int list
Argument: 1 : int
Reason: Value being applied does not have a function type
And I don't understand why because I have an almost identical function that multiplies values together which works just fine.
Your first pattern is defined in a curried way, whereas your second pattern uses a tuple way.
This ought to work:
Notice I changed the pattern a bit, since when the list is empty we really don’t care what is the increment.
The truth is that this is probably what
mapalready does, so most likely you can do away with the first pattern and just keep your mapping function pattern.But anyways, now you can do:
Or alternatively you can define both function patterns using parenthesis.