Skip to content

Instantly share code, notes, and snippets.

@xenophobia
Created July 20, 2014 19:32
Show Gist options
  • Save xenophobia/ceaf9727e363ac3f969d to your computer and use it in GitHub Desktop.
Save xenophobia/ceaf9727e363ac3f969d to your computer and use it in GitHub Desktop.
type
;; 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