fun inv ([], b) = b
| inv (h::t, b) = inv(t, h::b)
Note that you don't need pattern matching on the second list. This is a canonical example of a tail recursive function; it is the way to reverse a list with constant stack space. You error was using cons (::) where the first argument had type 'a list.