What could be the possible function foo, which has a type
’a * ’a -> int
in ML. i.e. a function which has the following type of the output
See Question&Answers more detail:osWhat could be the possible function foo, which has a type
’a * ’a -> int
in ML. i.e. a function which has the following type of the output
See Question&Answers more detail:osThis seems to be homework, so I give you a partial solution and some hints only. The type you want is a 'a * 'a -> int
, so the skeleton of a suitable function could be something like this (I assume you are using Standard ML):
fun foo(x, y) = ???
The ???
needs to meet two requirements: it must contain an expression that forces x
and y
to have the same type, and it must return an integer. The latter shouldn't be hard. For the former, there are many possibilities in SML, e.g., putting them in the same list, or returning them from the branches of the same if
or case
or handle
.