PasteRack.org
Paste # 92542
2017-12-02 12:42:41

Fork as a new paste.

Paste viewed 117 times.


Embed:

predicate for a recursive type

  1. #lang typed/racket/base
  2.  
  3. (define-type Simple-Packable
  4.   (U Void Boolean Bytes (Listof Simple-Packable)))
  5.  
  6. (: simple-packable? (-> Any Boolean : Simple-Packable))
  7. (define (simple-packable? x)
  8.   (cond
  9.     [(void?    x) #t]
  10.     [(boolean? x) #t]
  11.     [(bytes?   x) #t]
  12.     [(list?    x) ((inst andmap Any Boolean Simple-Packable) simple-packable? x)]
  13.     [else #f]))

=>