www

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

typed-prefab-declarations.rkt (939B)


      1 #lang typed/racket
      2 
      3 (struct (A) NonSexp ([v : A]) #:type-name NonSexpOf)
      4 (struct (A) NonSyntax ([v : A]) #:type-name NonSyntaxOf)
      5 (struct (A) Some ([v : A]))
      6 (define-type (Maybe A)
      7   (U (Some A) #f))
      8 
      9 (provide (struct-out NonSexp) NonSexpOf
     10          (struct-out NonSyntax) NonSyntaxOf
     11          (struct-out Some)
     12          Maybe)
     13 
     14 (module* test typed/racket
     15   (require (submod ".."))
     16   (require typed/rackunit)
     17   (check-pred procedure? NonSexp)
     18   (check-pred NonSexp? (ann (ann (NonSexp 1) (NonSexpOf Number)) Any))
     19   (check-not-exn
     20    (λ ()
     21      (ann (let ([n : (NonSexpOf Any) (NonSexp 1)])
     22             (if (number? (NonSexp-v n))
     23                 (NonSexp-v n)
     24                 0))
     25           Number)))
     26 
     27   (check-not-exn
     28    (λ ()
     29      (ann (let ([n : Any (NonSexp 1)])
     30             (if (NonSexp? n)
     31                 (if (number? (NonSexp-v n))
     32                     (NonSexp-v n)
     33                     2)
     34                 0))
     35           Number))))