In a type system with intersection types and contravariant subtyping of function argument types, you get case-lambda style functionality automatically. In that setting, you have results like:
add0=lambda().0
add1=lambda(x).x
add2=lambda(x,y).x+y
intersection(add0,add1,add2)=a function that takes 0, 1, or 2 arguments and adds them.
However, I've found implementing intersection types and full contravariance very tricky, so this isn't an economical solution if all you want is case-lambda.
|