www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

check-no-overlap.rkt (810B)


      1 #lang typed/racket
      2 (struct (A) st ([x : A]))
      3 (require phc-toolkit
      4          racket/format)
      5 
      6 (struct variant-no-overlap ())
      7 (define-syntax/parse (check-no-overlap τ₁ τ₂)
      8   #`(let ()
      9       (λ ([x : (U (∩ τ₁ τ₂) variant-no-overlap)])
     10         (cond
     11           [(variant-no-overlap? x) #t]
     12           [(typecheck-fail τ₁
     13                            #,(format "The types ~a and ~a seem to overlap"
     14                                      (syntax->datum #'τ₁)
     15                                      (syntax->datum #'τ₂)))]))
     16       (void)))
     17 
     18 
     19 (check-no-overlap (st Number) (st String))
     20 (check-no-overlap (st Negative-Integer) (st Byte))
     21 (check-not-tc
     22  #:message-regexp
     23  #rx"The types \\(st Nonpositive-Integer\\) and \\(st Byte\\) seem to overlap"
     24  (check-no-overlap (st Nonpositive-Integer) (st Byte)))