[racket-dev] how to define a custom "null" in typed racket
I know the code below is wrong because it sends TR into an infinite
loop. What is the recommended way to represent mynull (and its type)
without leaking its representation to a user of this library?
#lang typed/racket
(define mynull null)
(define-type MyListof (All (A) (Rec X (U mynull (Pair A X)))))
(: mynull? : (All (A) ((MyListof A) -> Boolean)))
(define (mynull? lst) (null? lst))
(: 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)))