You're on the right track. It looks like you've understood that there are two parts to this problem: forcing x
and y
to have the same type, and forcing foo
to return an integer.
You were close with fun foo (x,x) = 5;
. I think you probably meant something like this:
fun foo (x,y) = if x=y then 1 else 0;
This gives ''a * ''a -> int
, which is very close, but not quite what you need. ''a
is not the same as 'a
- while one dash means "any type", two dashes mean "any type which can be compared for equality". In other words, we've restricted the types just by saying x=y
.
You've identified one way of forcing the types to be the same: putting them in the result of an if
expression. Now all that's left is to turn the result of the if
(which has type 'a
) into an int
. You could do that by putting it in a case
expression, or passing it to another function with type 'a -> int
.
Or you could try something else. Every element in a list has to have the same type. So there's another way to restrict the types of x
and y
: put them in the same list. Then you've just got to figure out how to turn that list into an int
.