[racket] Typed racket: keywords and rest arguments

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Sat Mar 9 08:33:40 EST 2013

Greetings.

(this is a separate typed-racket question, and I think distinct from the questions I was asking last month)

I don't seem to be able to specify a type for a function with rest arguments and optional keywords.  The following fails to typecheck (Racket 5.3.3)

(: appender (String String * [#:k String] -> String))
(define (appender s1 #:k (v #f) . sx)
  (let loop ((l sx)
             (res (string-append s1 (or v "-x-"))))
    (if (null? l)
        res
        (loop (cdr l) (string-append res (car l))))))

-> Type Checker: Expected a function of type (case-> (String True String String * -> String) (False False String String * -> String)), but got a function with the wrong arity in: (define (appender s1 #:k (v #f) . sx) (let loop ((l sx) (res (string-append s1 (or v "-x-")))) (if (null? l) res (loop (cdr l) (string-append res (car l))))))

Similar functions work, with types (: appender (String String * -> String)) and (: appender (String String [#:k String] -> String)), so I don't think I'm messing up the syntax.

Best wishes,

Norman


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



Posted on the users mailing list.