www

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

typed-pairof-predicate.rkt (1027B)


      1 #lang typed/racket
      2 
      3 (provide pairof?)
      4 
      5 (require typed/racket/unsafe)
      6 (unsafe-require/typed racket/function
      7                       [[identity unsafe-cast-function] (∀ (A) (→ Any A))])
      8 (define-syntax-rule (unsafe-cast v t)
      9   ((inst unsafe-cast-function t) v))
     10 
     11 (: pairof?* (∀ (A D) (→ Any
     12                         (→ Any Boolean : A)
     13                         (→ Any Boolean : D)
     14                         Boolean)))
     15 (define (pairof?* v a? d?)
     16   (and (pair? v)
     17        (a? (car v))
     18        (d? (cdr v))))
     19 
     20 (define pairof?
     21   ;; Circumvent https://github.com/racket/typed-racket/issues/429
     22   (unsafe-cast pairof?*
     23                (∀ (A D) (→ Any
     24                            (→ Any Boolean : A)
     25                            (→ Any Boolean : D)
     26                            Boolean
     27                            :
     28                            ;; Circumvent
     29                            ;; https://github.com/racket/typed-racket/issues/488
     30                            #:+ (Pairof A D)
     31                            #:- (! (Pairof A D))))))