I am trying to reverse a list in SML with the following implementation
fun reverse x y =
case x of
[] => y
| x::xs => reverse(xs, x::y)
;
The error messages I get is impenetrable:
trial.sml:1.6-4.35 Error: case object and rules don't agree [tycon mismatch]
rule domain: 'Z list * 'Z list
object: ('Z list * 'Z list) * 'Y
in expression:
(case (arg,arg)
of (x,y) =>
(case x
of nil => y
| :: <pat> => reverse <exp>))
trial.sml:1.6-4.35 Error: right-hand-side of clause doesn't agree with function result type [tycon mismatch]
expression: 'Z -> _
result type: 'Y list
in declaration:
reverse = (fn arg => (fn <pat> => <exp>))
However if I change the signature to be fun reverse(x: 'a list, y: 'a list) then it works why is this so? Is there a way to write this so that I dont need to have to write the type 'a list ?