Created
July 20, 2014 19:32
-
-
Save xenophobia/ceaf9727e363ac3f969d to your computer and use it in GitHub Desktop.
type
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
;; map function | |
(define $map : [$A $B] ([(A -> B) {A}] -> {B}) | |
(lambda [$fn $xs] | |
(match xs (list something) | |
{[<nil> {}] | |
[<cons $x $rs> {(fn x) @(map fn rs)}]}))) | |
;; Ord type class | |
(type $Ordering {<Less> <Equal> <Greater>}) | |
(define $ordering : (Matcher Ordering) | |
(algebraic-data-matcher | |
{<less> <equal> <greater>})) | |
(class $Ord $A :: Eq | |
{$lt? : ([A A] -> Bool)} | |
{[$lte? : ([A A] -> Bool) (lambda [$x $y] (or (lt? x y) (eq? x y)))] | |
[$gte? : ([A A] -> Bool) (lt? $2 $1)] | |
[$gt? : ([A A] -> Bool) (lte? $2 $1)] | |
[$compare : ([A A] -> Ordering) | |
(lambda [$m $n] | |
(if (lt? m n) | |
<Less> | |
(if (eq? m n) | |
<Equal> | |
<Greater>)))]}) | |
(instance Integer Ord {[$lt? lt-integer?]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment