Skip to content

Instantly share code, notes, and snippets.

@aboekhoff
Created September 1, 2010 18:32
Show Gist options
  • Save aboekhoff/561122 to your computer and use it in GitHub Desktop.
Save aboekhoff/561122 to your computer and use it in GitHub Desktop.
;;;; pairs
(define-type Pair a b)
(define-type Empty)
(define Pair:foldl
f x (Pair a b) -> (foldl f (f x a) b))
(define Pair:first
(Pair a _) -> (Some a))
(define Pair:rest
(Pair _ (Empty)) -> Empty
(Pair _ a) -> a)
;;;; snip
(define-interface Foldable
foldl XS (F X XS)
foldr XS (F X XS))
(extend-interface Foldable
array
(foldl array:foldl)
(foldr array:foldr)
array-like
(foldl array:foldl)
(foldr array:foldr)
Pair
(foldl Pair:foldl)
Empty
(foldl (fn (_ X _) X)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment