Adjust named-let to use the return type annotation whenever possible

Fixes #43
This commit is contained in:
Alexis King 2015-03-04 14:55:54 -08:00
parent 33543ce054
commit c79b61a751
2 changed files with 34 additions and 20 deletions

View File

@ -439,26 +439,29 @@ This file defines two sorts of primitives. All of them are provided into any mod
(~and (~seq (~optional (~seq : ret-ty))
(bs:optionally-annotated-binding ...) body ...)
(~seq rest ...)))
(quasisyntax/loc stx
(#,(syntax-parse #'(rest ...)
#:literals (:)
[(: ret-ty (bs:annotated-binding ...) . body)
(quasisyntax/loc stx
(-letrec ([nm : (bs.ty ... -> ret-ty)
#,(quasisyntax/loc stx
(lambda (bs.ann-name ...) . #,(syntax/loc stx body)))])
#,(quasisyntax/loc stx nm)))]
[(: ret-ty (bs:optionally-annotated-binding ...) body ... bod)
(quasisyntax/loc stx
(letrec ([nm #,(quasisyntax/loc stx
(lambda (bs.ann-name ...) body ... (ann #,(syntax/loc stx bod) ret-ty)))])
#,(quasisyntax/loc stx nm)))]
[((bs:optionally-annotated-binding ...) . body)
(quasisyntax/loc stx
(letrec ([nm #,(quasisyntax/loc stx
(lambda (bs.ann-name ...) . #,(syntax/loc stx body)))])
#,(quasisyntax/loc stx nm)))])
bs.rhs ...))]
(syntax-parse #'(rest ...)
#:literals (:)
[(: ret-ty (bs:annotated-binding ...) . body)
(quasisyntax/loc stx
((-letrec ([nm : (bs.ty ... -> ret-ty)
#,(quasisyntax/loc stx
(lambda (bs.ann-name ...) . #,(syntax/loc stx body)))])
#,(quasisyntax/loc stx nm))
bs.rhs ...))]
[(: ret-ty (bs:optionally-annotated-binding ...) body ... bod)
(quasisyntax/loc stx
(ann
((letrec ([nm #,(quasisyntax/loc stx
(lambda (bs.ann-name ...) body ... (ann #,(syntax/loc stx bod) ret-ty)))])
#,(quasisyntax/loc stx nm))
bs.rhs ...)
ret-ty))]
[((bs:optionally-annotated-binding ...) . body)
(quasisyntax/loc stx
((letrec ([nm #,(quasisyntax/loc stx
(lambda (bs.ann-name ...) . #,(syntax/loc stx body)))])
#,(quasisyntax/loc stx nm))
bs.rhs ...))])]
[(-let vars:lambda-type-vars
([bn:optionally-annotated-name e] ...)
. rest)

View File

@ -0,0 +1,11 @@
#lang typed/racket
(let loop : Integer ([n 10])
(cond
[(= n 5) n]
[else (loop (sub1 n))]))
(let loop : Integer ([n : Integer 10])
(cond
[(= n 5) n]
[else (loop (sub1 n))]))