[racket] Typed racket and keywords

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Wed Feb 20 17:48:01 EST 2013

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)

-- 
Norman Gray  :  http://nxg.me.uk
SUPA School of Physics and Astronomy, University of Glasgow, UK



Posted on the users mailing list.