[racket] opt-lambda: does not type check when defaults are provided

From: Vincent St-Amour (stamourv at ccs.neu.edu)
Date: Sat Sep 24 16:06:19 EDT 2011

At Sat, 24 Sep 2011 15:02:44 -0400 (EDT),
Jeremiah Willcock wrote:
> 
> The following program:
> 
> #lang typed/racket
> (opt-lambda: ((a : Symbol 'foo)) a)
> 
> does not type check with the current Git version of Racket, producing the 
> following error:
> 
> opt-bug.rkt:2:0: Type Checker: Error in macro expansion -- insufficient 
> type information to typecheck. please add more type annotations in: 
> (opt-lambda: ((a : Symbol (quote foo))) a)
> 
> It would seem that the opt-lambda: expression should have a well-defined 
> type.

This version works:
(ann (opt-lambda: ((a : Symbol 'foo)) a)
     (case-> (-> Symbol) (Symbol -> Symbol)))

Currently, in addition to the argument types, you need to provide the
type of the entire function.

Top-level annotations also work:
(: my-function (case-> (-> Symbol) (Symbol -> Symbol)))
(define my-function (opt-lambda: ((a : Symbol 'foo)) a))

This is due to limitations of opt-lambda:. I'll see what I can do
about it.

> On a similar note, the untyped syntax (lambda ((a 5)) ...) for defaults 
> does not work in Typed Racket.
> 
> Is there something I'm doing incorrectly, or is this a bug?  Thank you for 
> your help.

That's correct. The typechecker cannot currently handle the expansion
of lambdas with optional arguments, so Typed Racket disallows them.

Vincent


Posted on the users mailing list.