[racket-dev] how to define a custom "null" in typed racket
Perhaps something like this?
;;;;;;;;;;;;;
#lang typed/racket/base
(provide mynull mycar mycdr)
(struct: MyNull ())
(define mynull (MyNull))
(define-type MyListof (All (A) (Rec X (U MyNull (Pair A X)))))
(: mycar : (All (A) ((MyListof A) -> A)))
(define (mycar lst)
(if (MyNull? lst)
(error 'mycar "given list is empty")
(car lst)))
(: mycdr : (All (A) ((MyListof A) -> (MyListof A))))
(define (mycdr lst)
(if (MyNull? lst)
(error 'mycdr "given list is empty")
(cdr lst)))
;;;;;;;;;;;;;
where mynull is the singleton instance of the opaque structure type MyNull.