In Scala it is possible, so I wonder if this possible in SML as well, consider such code:
fun in_list(elem,coll) =
case coll of
[] => false
| elem :: tail => true
| head :: tail => in_list(elem,tail);
In the second line of case I would like to use elem from the arguments, but SML treats it as a placeholder and throw an error on redundant case (the third line).
So — is it possible to use elem here and if yes, how?
No, it’s not possible. You’ll have to use an
if:Or, in this case, you could also use logical operators instead of an
if: