Last active
December 18, 2015 00:58
-
-
Save takikawa/5700153 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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