[racket] Typed racket and keywords
Neil, hello.
On 2013 Feb 21, at 03:49, Neil Toronto <neil.toronto at gmail.com> wrote:
> Well, you can't do it like that, but you can like this:
>
> #lang typed/racket
>
> (: test0 (Integer [#:zero Integer] -> Boolean))
> (define (test0 x #:zero [v 0])
> (= x v))
Aha -- that's certainly a neater way of doing it. Thanks!
There may be a documentation lacuna, however, since that form seems to be not straightforwardly deducible from the Typed Racket reference (v5.3.3).
Section 1.6, Other Type Constructors <http://docs.racket-lang.org/ts-reference/type-ref.html#%28part._.Other_.Type_.Constructors%29>, describes four forms of function type, but doesn't include any optional arguments (I presumed that such optional parts had to be typed explicitly with case->). 'dom' isn't defined there (I guessed it could refer only to an individual type), and the 'dom' of <http://docs.racket-lang.org/reference/function-contracts.html> doesn't match. Even the 'optional-dom' of the ->* description doesn't fit the form above.
Similarly, the opt-lambda: of <http://docs.racket-lang.org/ts-reference/special-forms.html#(part._.Anonymous_.Functions)> includes optional arguments, but doesn't appear to permit keywords.
The (Integer [#:zero Integer] -> Boolean) form is pretty intuitive, though, and I should have experimented more, but I confess to being an incorrigible obsessive about manuals (new fridge, new phone: "Oh, look, what nice manual, I'll turn the gadget on later...").
All the best,
Norman
--
Norman Gray : http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK