Skip to content

Instantly share code, notes, and snippets.

@samth
Created October 25, 2011 20:14
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/1314097 to your computer and use it in GitHub Desktop.
Save samth/1314097 to your computer and use it in GitHub Desktop.
Producing explicit type errors for uncovered cases in Typed Racket
#lang typed/racket
(define-syntax (cond* stx)
(syntax-case stx ()
[(_ x clause ...)
#`(cond clause ... [else (typecheck-fail #,stx "incomplete coverage" #:covered-id x)])]))
(: f : (U String Integer) -> Boolean)
(define (f x)
(cond* x
[(string? x) #t]
[(exact-nonnegative-integer? x) #f]))
;; Produces the error:
;; Type Checker: incomplete coverage; missing coverage of Negative-Integer in:
;; (cond* x ((string? x) #t) ((exact-nonnegative-integer? x) #f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment