Created
June 19, 2011 02:39
-
-
Save tonyg/1033686 to your computer and use it in GitHub Desktop.
Pattern-matching over objects using views and coviews
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
(define-language <list> | |
(Nil) | |
(Cons first rest)) | |
(define-language <maybe> | |
(Nothing) | |
(Just value)) | |
(define-language <tsil> | |
(Snoc butlast last)) | |
(extend-behaviour <list> | |
(object self | |
((meta (coerce '<tsil>)) | |
(ocase self | |
((Cons a (Nil)) (Just (Snoc (Nil) a))) | |
((Cons a (Snoc b c)) (Just (Snoc (Cons a b) c))) | |
(_ (Nothing)))))) | |
(extend-behaviour <tsil> | |
(object self | |
((meta (coerce '<list>)) | |
(ocase self | |
((Snoc (Nil) a) (Just (Cons a (Nil)))) | |
((Snoc (Cons a b) c) (Just (Cons a (Snoc b c)))) | |
(_ (Nothing)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment