I am trying to write a function to swap a pair of tuples inside of a list like this:
- pairSwap [(1, 2), (3, 4), (5, 6);
[(2,1),(4,3),(6,5)]
I am having a hard time figuring out what I am doing wrong with my syntax while declaring the function. This is what I have so far:
fun pairSwap ((a : 'a, b: 'a) list) : (('a, 'a) list) =
...
;
Where am I going wrong?
Edit: Solution
fun pairSwap (t : ('a * 'a) list) : ('a * 'a) list =
if null t
then []
else
let
val v = hd t
in
(#2 v, #1 v)::pairSwap (tl t)
end
;