The type signature tells you to have a list of pairs of integers. An example of a pair of ints would be (4,1)
. A list of pairs would then be [(a,b),(c,d),...]
, and not, as you've tried, a pair of lists of integers.
I'm sure you're familiar with the (x::xs)
notation, since you seem to understand lists to some degree. If we are to match into pairs we can do it like this: ((n,m)::xs)
. This pattern will bind n and m to the corresponding ints and xs to the rest of the list. Then recursion is straightforward:
fun pInts [] = ()
| pInts ((n,m)::xs) = print ("(" ^ Int.toString n ^ ", " Int.toString m ^ ")";
pInts xs
The important thing to glean from this is that you can bind several variables in a single pattern and use them in your functions. You can even, if you're sure you have more than one element in a list, bind several elements at once:
fun pairs [] = []
| pairs [x] = []
| pairs (x::y::xs) = (x,y) :: pairs xs