Skip to content

Instantly share code, notes, and snippets.

@samth
Last active December 14, 2015 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samth/5009113 to your computer and use it in GitHub Desktop.
Save samth/5009113 to your computer and use it in GitHub Desktop.
Restricting the keywords
#lang typed/racket
(: f (case->
(Integer [#:application Integer] [#:context Nothing] -> (List Integer Integer))
(Integer [#:context Integer] [#:application Nothing] -> (List Integer Integer))))
(define (f x #:application [a 0] #:context [c 0])
(list a c))
(f 1)
(f 1 #:application 5)
(f 1 #:context 5)
(f 1 #:application 5 #:context 5) ;; doesn't typecheck
#lang typed/racket
(: f (Integer [#:application Integer] [#:context Integer]
-> (List Integer Integer)))
(define (f x #:application [#{a : (U Integer #f)} #f] #:context [#{c : (U Integer #f)} #f])
(cond [(and a c) (error "too many keywords")]
[a (list a 0)]
[c (list 0 c)]
[else (list 0 0)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment