![]() Keyword functions are a little tricky. This PR addresses issues checking the body of kw functions. Basically, a function with keyword arguments such as inc: (define (inc x #:n [n 1]) (+ x n)) actually expands into a more complex function with 3 arguments that looks something resembling the following: (define (inc-expanded n* n-given? x) (let ([n (if n-given? n* 1)]) (+ x n))) and calls to inc are converted to match this form: (inc 42) => (inc-expanded #f #f 42) (inc 42 #:n 2) => (inc-expanded 2 #t 42) Note that each optional keyword argument has a boolean flag argument that signals whether or not the caller provided that keyword argument. This PR takes advantage of the observation that the value for the n* argument in inc is only reachable in code when n-given? is #t, and so, assuming the kw-expansion protocol always only accesses n* if n-given? is #t, we can actually safely check the body of the function against the following simple but correct type: (-> Number Boolean Number Number) An alternative previous approach expanded the function type into every possible combination of optional argument and optional argument flag, but this was prohibitively expensive. |
||
---|---|---|
source-syntax | ||
typed-racket | ||
typed-racket-compatibility | ||
typed-racket-doc | ||
typed-racket-lib | ||
typed-racket-more | ||
typed-racket-test | ||
.gitignore | ||
.travis.yml | ||
issue_template.md | ||
README.md |
Typed Racket
Typed Racket is Racket's gradually-typed sister language which lets you add statically-checked type annotations to your programs. For more information, see the Typed Racket Guide.
Installation
Typed Racket is bundled in the default Racket distribution, which you can download from Racket's download page.
You can also manually install it from the main package catalog with the following command:
raco pkg install typed-racket
Documentation
- Guide: http://docs.racket-lang.org/ts-guide/index.html
- Reference: http://docs.racket-lang.org/ts-reference/index.html
The documentation is also bundled in your local copy of Typed Racket.
Copyright (c) 2010-2015 PLT Design Inc.
This package is distributed under the GNU Lesser General Public License (LGPL). This means that you can link this package into proprietary applications, provided you follow the rules stated in the LGPL. You can also modify this package; if you distribute a modified version, you must distribute it under the terms of the LGPL, which in particular means that you must release the source code for the modified software. See http://www.gnu.org/copyleft/lesser.html for more information.