[racket] Typed racket and keywords

From: Neil Toronto (neil.toronto at gmail.com)
Date: Wed Feb 20 22:49:02 EST 2013

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))

I think the `Keyword' type is for symbols that happen to be keywords:

   (cast '#:zero Keyword)

I believe there is currently no way to type a function that has required 
keywords; i.e. they have to be optional.

Neil ⊥

On 02/20/2013 03:48 PM, Norman Gray wrote:
>
> Greetings.
>
> Should I be able to specify a function which can take keywords, in Typed Racket?
>
> The 'define:' form suggests not, and an experiment with:
>
> (define test0
>    (case-lambda:
>      (((x : Integer))
>       (= x 0))
>      (((x : Integer)
>        (k : Keyword)
>        (v : Integer))
>       (begin
>         (eprintf "x=~s  k=~s  v=~s~%" x k v)
>         (= x v)))))
>
> similarly suggests not.  I get
>
>> (test0 1 #:keyword 1)
> Type Checker: No function domains matched in function application:
> Domains: Integer
>           Integer Keyword Integer
> Arguments: One
>   in: (test0 1 #:keyword 1)
>>
>
> I'm guessing that the recommended alternative would be
>
> (define test0
>    (case-lambda:
>      (((x : Integer))
>       (= x 0))
>      (((x : Integer)
>        (k : (U 'k1 'k2))
>        (v : Integer))
>       (begin
>         (eprintf "x=~s  k=~s  v=~s~%" x k v)
>         (= x v)))))
>
> Would that be right?
>
> And what would be good style here? (I can broadly see why keywords might be difficult or low-priority in this context, so I suppose that the style question is the main thing here)
>
> I can't see any use of 'Keyword' in the tree under collects/typed.
>
> Thanks for any illumination.
>
> All the best,
>
> Norman
> (having another go with Typed Racket)
>


Posted on the users mailing list.