Drop backslash from lambda definitions
This commit is contained in:
64
lib/base.tri
64
lib/base.tri
@ -1,74 +1,74 @@
|
||||
false = t
|
||||
_ = t
|
||||
true = t t
|
||||
id = \a : a
|
||||
const = \a b : a
|
||||
id = a : a
|
||||
const = a b : a
|
||||
pair = t
|
||||
if = \cond then else : t (t else (t t then)) t cond
|
||||
if = cond then else : t (t else (t t then)) t cond
|
||||
|
||||
y = ((\mut wait fun : wait mut (\x : fun (wait mut x)))
|
||||
(\x : x x)
|
||||
(\a0 a1 a2 : t (t a0) (t t a2) a1))
|
||||
y = ((mut wait fun : wait mut (x : fun (wait mut x)))
|
||||
(x : x x)
|
||||
(a0 a1 a2 : t (t a0) (t t a2) a1))
|
||||
|
||||
compose = \f g x : f (g x)
|
||||
compose = f g x : f (g x)
|
||||
|
||||
triage = \leaf stem fork : t (t leaf stem) fork
|
||||
test = triage "Leaf" (\_ : "Stem") (\_ _ : "Fork")
|
||||
triage = leaf stem fork : t (t leaf stem) fork
|
||||
test = triage "Leaf" (_ : "Stem") (_ _ : "Fork")
|
||||
|
||||
matchBool = (\ot of : triage
|
||||
matchBool = (ot of : triage
|
||||
of
|
||||
(\_ : ot)
|
||||
(\_ _ : ot)
|
||||
(_ : ot)
|
||||
(_ _ : ot)
|
||||
)
|
||||
|
||||
lAnd = (triage
|
||||
(\_ : false)
|
||||
(\_ x : x)
|
||||
(\_ _ x : x))
|
||||
(_ : false)
|
||||
(_ x : x)
|
||||
(_ _ x : x))
|
||||
|
||||
lOr = (triage
|
||||
(\x : x)
|
||||
(\_ _ : true)
|
||||
(\_ _ _ : true))
|
||||
(x : x)
|
||||
(_ _ : true)
|
||||
(_ _ _ : true))
|
||||
|
||||
matchPair = \a : triage _ _ a
|
||||
matchPair = a : triage _ _ a
|
||||
|
||||
not? = matchBool false true
|
||||
and? = matchBool id (\_ : false)
|
||||
and? = matchBool id (_ : false)
|
||||
|
||||
or? = (\x z :
|
||||
or? = (x z :
|
||||
matchBool
|
||||
(matchBool true true z)
|
||||
(matchBool true false z)
|
||||
x)
|
||||
|
||||
xor? = (\x z :
|
||||
xor? = (x z :
|
||||
matchBool
|
||||
(matchBool false true z)
|
||||
(matchBool true false z)
|
||||
x)
|
||||
|
||||
equal? = y (\self : triage
|
||||
equal? = y (self : triage
|
||||
(triage
|
||||
true
|
||||
(\_ : false)
|
||||
(\_ _ : false))
|
||||
(\ax :
|
||||
(_ : false)
|
||||
(_ _ : false))
|
||||
(ax :
|
||||
triage
|
||||
false
|
||||
(self ax)
|
||||
(\_ _ : false))
|
||||
(\ax ay :
|
||||
(_ _ : false))
|
||||
(ax ay :
|
||||
triage
|
||||
false
|
||||
(\_ : false)
|
||||
(\bx by : lAnd (self ax bx) (self ay by))))
|
||||
(_ : false)
|
||||
(bx by : lAnd (self ax bx) (self ay by))))
|
||||
|
||||
succ = y (\self :
|
||||
succ = y (self :
|
||||
triage
|
||||
1
|
||||
t
|
||||
(triage
|
||||
(t (t t))
|
||||
(\_ tail : t t (self tail))
|
||||
(_ tail : t t (self tail))
|
||||
t))
|
||||
|
72
lib/list.tri
72
lib/list.tri
@ -1,68 +1,68 @@
|
||||
!import "base.tri" !Local
|
||||
|
||||
matchList = \a b : triage a _ b
|
||||
matchList = a b : triage a _ b
|
||||
|
||||
emptyList? = matchList true (\_ _ : false)
|
||||
head = matchList t (\head _ : head)
|
||||
tail = matchList t (\_ tail : tail)
|
||||
emptyList? = matchList true (_ _ : false)
|
||||
head = matchList t (head _ : head)
|
||||
tail = matchList t (_ tail : tail)
|
||||
|
||||
append = y (\self : matchList
|
||||
(\k : k)
|
||||
(\h r k : pair h (self r k)))
|
||||
append = y (self : matchList
|
||||
(k : k)
|
||||
(h r k : pair h (self r k)))
|
||||
|
||||
lExist? = y (\self x : matchList
|
||||
lExist? = y (self x : matchList
|
||||
false
|
||||
(\h z : or? (equal? x h) (self x z)))
|
||||
(h z : or? (equal? x h) (self x z)))
|
||||
|
||||
map_ = y (\self :
|
||||
map_ = y (self :
|
||||
matchList
|
||||
(\_ : t)
|
||||
(\head tail f : pair (f head) (self tail f)))
|
||||
map = \f l : map_ l f
|
||||
(_ : t)
|
||||
(head tail f : pair (f head) (self tail f)))
|
||||
map = f l : map_ l f
|
||||
|
||||
filter_ = y (\self : matchList
|
||||
(\_ : t)
|
||||
(\head tail f : matchBool (t head) id (f head) (self tail f)))
|
||||
filter = \f l : filter_ l f
|
||||
filter_ = y (self : matchList
|
||||
(_ : t)
|
||||
(head tail f : matchBool (t head) id (f head) (self tail f)))
|
||||
filter = f l : filter_ l f
|
||||
|
||||
foldl_ = y (\self f l x : matchList (\acc : acc) (\head tail acc : self f tail (f acc head)) l x)
|
||||
foldl = \f x l : foldl_ f l x
|
||||
foldl_ = y (self f l x : matchList (acc : acc) (head tail acc : self f tail (f acc head)) l x)
|
||||
foldl = f x l : foldl_ f l x
|
||||
|
||||
foldr_ = y (\self x f l : matchList x (\head tail : f (self x f tail) head) l)
|
||||
foldr = \f x l : foldr_ x f l
|
||||
foldr_ = y (self x f l : matchList x (head tail : f (self x f tail) head) l)
|
||||
foldr = f x l : foldr_ x f l
|
||||
|
||||
length = y (\self : matchList
|
||||
length = y (self : matchList
|
||||
0
|
||||
(\_ tail : succ (self tail)))
|
||||
(_ tail : succ (self tail)))
|
||||
|
||||
reverse = y (\self : matchList
|
||||
reverse = y (self : matchList
|
||||
t
|
||||
(\head tail : append (self tail) (pair head t)))
|
||||
(head tail : append (self tail) (pair head t)))
|
||||
|
||||
snoc = y (\self x : matchList
|
||||
snoc = y (self x : matchList
|
||||
(pair x t)
|
||||
(\h z : pair h (self x z)))
|
||||
(h z : pair h (self x z)))
|
||||
|
||||
count = y (\self x : matchList
|
||||
count = y (self x : matchList
|
||||
0
|
||||
(\h z : matchBool
|
||||
(h z : matchBool
|
||||
(succ (self x z))
|
||||
(self x z)
|
||||
(equal? x h)))
|
||||
|
||||
last = y (\self : matchList
|
||||
last = y (self : matchList
|
||||
t
|
||||
(\hd tl : matchBool
|
||||
(hd tl : matchBool
|
||||
hd
|
||||
(self tl)
|
||||
(emptyList? tl)))
|
||||
|
||||
all? = y (\self pred : matchList
|
||||
all? = y (self pred : matchList
|
||||
true
|
||||
(\h z : and? (pred h) (self pred z)))
|
||||
(h z : and? (pred h) (self pred z)))
|
||||
|
||||
any? = y (\self pred : matchList
|
||||
any? = y (self pred : matchList
|
||||
false
|
||||
(\h z : or? (pred h) (self pred z)))
|
||||
(h z : or? (pred h) (self pred z)))
|
||||
|
||||
intersect = \xs ys : filter (\x : lExist? x ys) xs
|
||||
intersect = xs ys : filter (x : lExist? x ys) xs
|
||||
|
@ -1,36 +1,36 @@
|
||||
!import "list.tri" !Local
|
||||
|
||||
match_ = y (\self value patterns :
|
||||
match_ = y (self value patterns :
|
||||
triage
|
||||
t
|
||||
(\_ : t)
|
||||
(\pattern rest :
|
||||
(_ : t)
|
||||
(pattern rest :
|
||||
triage
|
||||
t
|
||||
(\_ : t)
|
||||
(\test result :
|
||||
(_ : t)
|
||||
(test result :
|
||||
if (test value)
|
||||
(result value)
|
||||
(self value rest))
|
||||
pattern)
|
||||
patterns)
|
||||
|
||||
match = (\value patterns :
|
||||
match_ value (map (\sublist :
|
||||
match = (value patterns :
|
||||
match_ value (map (sublist :
|
||||
pair (head sublist) (head (tail sublist)))
|
||||
patterns))
|
||||
|
||||
otherwise = const (t t)
|
||||
|
||||
matchExample = (\x : match x
|
||||
[[(equal? 1) (\_ : "one")]
|
||||
[(equal? 2) (\_ : "two")]
|
||||
[(equal? 3) (\_ : "three")]
|
||||
[(equal? 4) (\_ : "four")]
|
||||
[(equal? 5) (\_ : "five")]
|
||||
[(equal? 6) (\_ : "six")]
|
||||
[(equal? 7) (\_ : "seven")]
|
||||
[(equal? 8) (\_ : "eight")]
|
||||
[(equal? 9) (\_ : "nine")]
|
||||
[(equal? 10) (\_ : "ten")]
|
||||
[ otherwise (\_ : "I ran out of fingers!")]])
|
||||
matchExample = (x : match x
|
||||
[[(equal? 1) (_ : "one")]
|
||||
[(equal? 2) (_ : "two")]
|
||||
[(equal? 3) (_ : "three")]
|
||||
[(equal? 4) (_ : "four")]
|
||||
[(equal? 5) (_ : "five")]
|
||||
[(equal? 6) (_ : "six")]
|
||||
[(equal? 7) (_ : "seven")]
|
||||
[(equal? 8) (_ : "eight")]
|
||||
[(equal? 9) (_ : "nine")]
|
||||
[(equal? 10) (_ : "ten")]
|
||||
[ otherwise (_ : "I ran out of fingers!")]])
|
||||
|
Reference in New Issue
Block a user