typed-racket icon indicating copy to clipboard operation
typed-racket copied to clipboard

case-lambda allows multiple cases with the same arity

Open gfbee opened this issue 8 years ago • 5 comments

[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.

gfbee avatar Mar 24 '17 04:03 gfbee

I think this is a doc bug -- that case is allowed.

samth avatar Oct 05 '17 19:10 samth

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

bennn avatar Oct 06 '17 03:10 bennn

Right, but case-> is a type constructor and case-lambda, which this report is about, is a term constructor.

samth avatar Oct 06 '17 12:10 samth

@gfbee is this still an issue?

spdegabrielle avatar Sep 18 '19 15:09 spdegabrielle

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.

bennn avatar Sep 19 '19 14:09 bennn