typed-racket
typed-racket copied to clipboard
case-lambda allows multiple cases with the same arity
[I originally opened this as an issue for racket, but it more clearly violates the docs for typed/racket.]
Although for racket it doesn't seem explicitly forbidden, the typed/racket docs say:
Note that each formals must have a different arity.
Should this perhaps be an expansion-time error:
> (case-lambda [([z : Zero]) z]
[([o : One]) o])
- : (-> Zero Zero)
This came up because a student encountering the case-> type constructor wondered whether case-lambda would provide overloading by type.
I think this is a doc bug -- that case is allowed.
Note that the case-> formals must (currently) have a different arity if the type is being used to describe an untyped function:
#lang typed/racket/base
(require/typed racket/base
(values
(case-> (-> Integer Integer)
(-> Symbol Symbol))))
;; Type Checker: Type .... could not be converted to a contract: function type has two cases of arity 1
Right, but case-> is a type constructor and case-lambda, which this report is about, is a term constructor.
@gfbee is this still an issue?
Yes this is still an issue on Racket 7.4. The code runs the same and the docs make the same statement about formals and arity.