1

I am new to ML, and wanted to use case expressions and pattern matching in the following way.

fun myFun(a,b) = myFun(a,b,[])
|   myFun(a,b,c) = (*do something here*)
|   myFun(a,b,d) = (*do something here as well*);

so is it possible to have different number of parameters as given in this example?

Thanks.

Huzo
  • 1,652
  • 1
  • 21
  • 52

1 Answers1

3

All ML functions take exactly one parameter, even if that parameter happens to be a tuple.

(ML programmers sometimes speak of "multiple" parameters, slightly abusing terminology. It does not mean quite the same thing as in other languages, and what's considered "multiple" or not is more a question of perspective than of syntax.)

All clauses in a definition must also have the same type, so your clauses must all have the same tuple type as their parameter.

It looks like you're aiming for something like the "default arguments" that some languages have, but there is no such thing in Standard ML.

molbdnilo
  • 64,751
  • 3
  • 43
  • 82