I have the code below, and I am confused on why it is not compiling. I understood pattern matching can be used to match against different kinds of constructors, and as long as the expressions on the right side return the same type, it should be fine. But this is not happening below. Could someone please explain this?
fun myfunc (s: string, lst: string list) =
let fun f (s, []) = NONE
| f (s, x::xs') = SOME ["list"]
| f (s, SOME(x::xs')) = SOME ["some"]
in
f(s, lst)
end
When trying to run this code, the compiler throws an error stating
hw2provided.sml:25.13-27.46 Error: parameter or result constraints of clauses don't agree [tycon mismatch]
this clause: 'Z * 'Y list option -> 'X
previous clauses: 'Z * 'W list -> 'X
in declaration:
filter =
(fn (s,nil) => NONE
| (s,:: <pat>) => SOME (<exp> :: <exp>)
| (s,SOME <pat>) => SOME (<exp> :: <exp>))