Skip to content

Instantly share code, notes, and snippets.

@takikawa
Last active December 18, 2015 00:58
Show Gist options
  • Save takikawa/5700153 to your computer and use it in GitHub Desktop.
Save takikawa/5700153 to your computer and use it in GitHub Desktop.
#lang typed/racket
;; from Wikipedia
(struct: (A B) :<: ([left : A] [right : B])
#:transparent)
(struct: Epsilon ())
(define-type (Nested A)
(U (:<: A (Nested (Listof A))) Epsilon))
(: nested (Nested Integer))
(define nested
(:<: 1 (:<: (list 2 3 4) (:<: (list (list 4 5) (list 7) (list 8 9)) (Epsilon)))))
;; inference loops forever for this one...
(: nested-length (All (A) ((Nested A) -> Integer)))
(define (nested-length n)
(if (Epsilon? n)
0
(add1 ((inst nested-length (Listof A)) (:<:-right n)))))
(provide nested nested-length :<: Nested Epsilon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment