new tld syntax

This commit is contained in:
Victor Taelin 2024-07-08 18:13:17 -03:00
parent e20170a8bb
commit bf2d62a572
129 changed files with 996 additions and 670 deletions

View File

@ -1,3 +1,4 @@
BMap/leaf
: ∀(A: *) (BMap A)
= λA ~λP λnode λleaf leaf
λA ~λP λnode λleaf leaf

Before

Width:  |  Height:  |  Size: 61 B

After

Width:  |  Height:  |  Size: 60 B

View File

@ -4,5 +4,6 @@ BMap/node
∀(val: A)
∀(rgt: (BMap A))
(BMap A)
= λA λlft λval λrgt
~λP λnode λleaf (node lft val rgt)
λA λlft λval λrgt
~λP λnode λleaf (node lft val rgt)

Before

Width:  |  Height:  |  Size: 153 B

After

Width:  |  Height:  |  Size: 150 B

View File

@ -1,7 +1,11 @@
use Bool/{true,false,and}
and (a: Bool) (b: Bool) : Bool =
match a {
true: b
false: false
}
and
- a: Bool
- b: Bool
: Bool
match a {
true: b
false: false
}

View File

@ -1,2 +1,4 @@
false : Bool =
~λP λt λf f
false
: Bool
~λP λt λf f

View File

@ -1,7 +1,13 @@
use Bool/{true,false}
if (b: Bool) (P: *) (t: P) (f: P) : P =
match b {
true: t
false: f
}
if
- b: Bool
- P: *
- t: P
- f: P
: P
match b {
true: t
false: f
}

View File

@ -1,9 +1,10 @@
use Bool/{true,false}
match
(P: ∀(x: Bool) *)
(t: (P true))
(f: (P false))
(b: Bool)
- P: ∀(x: Bool) *
- t: (P true)
- f: (P false)
- b: Bool
: (P b)
= (~b P t f)
(~b P t f)

View File

@ -1,7 +1,10 @@
use Bool/{true,false}
not (x: Bool) : Bool =
match x {
true: false
false: true
}
not
- x: Bool
: Bool
match x {
true: false
false: true
}

View File

@ -1,7 +1,11 @@
use Bool/{true,false}
or (a: Bool) (b: Bool) : Bool =
match a {
true: true
false: b
}
or
- a: Bool
- b: Bool
: Bool
match a {
true: true
false: b
}

View File

@ -1,7 +1,10 @@
use Bool/{true,false}
show (x: Bool) : String =
match x {
true: "true"
false: "false"
}
show
- x: Bool
: String
match x {
true: "true"
false: "false"
}

View File

@ -1,2 +1,4 @@
true : Bool =
~λP λt λf t
true
: Bool
~λP λt λf t

View File

@ -1,2 +1,6 @@
equal (a: Char) (b: Char) : Bool =
(U48/equal a b)
equal
- a: Char
- b: Char
: Bool
(U48/equal a b)

View File

@ -1,4 +1,9 @@
is_between (min: Char) (max: Char) (chr: Char) : Bool =
(Bool/and
(U48/to_bool (>= chr min))
(U48/to_bool (<= chr max)))
is_between
- min: Char
- max: Char
- chr: Char
: Bool
(Bool/and
(U48/to_bool (>= chr min))
(U48/to_bool (<= chr max)))

View File

@ -1,2 +1,5 @@
is_blank (a: Char) : Bool =
(Bool/or (Char/equal a 10) (Char/equal a 32))
is_blank
- a: Char
: Bool
(Bool/or (Char/equal a 10) (Char/equal a 32))

View File

@ -1,2 +1,5 @@
is_decimal (a: Char) : Bool =
(Char/is_between 48 57 a)
is_decimal
- a: Char
: Bool
(Char/is_between 48 57 a)

View File

@ -1,13 +1,14 @@
use Bool/{true,false,or}
use Char/{is_between,equal}
is_name (a: Char) : Bool =
(or (is_between 97 122 a)
(or (is_between 65 90 a)
(or (is_between 48 57 a)
(or (equal 95 a)
(or (equal 46 a)
(or (equal 45 a)
false))))))
is_name
- a: Char
: Bool
(or (is_between 97 122 a)
(or (is_between 65 90 a)
(or (is_between 48 57 a)
(or (equal 95 a)
(or (equal 46 a)
(or (equal 45 a)
false))))))

View File

@ -1,2 +1,5 @@
is_newline (a: Char) : Bool =
(Char/equal a 10)
is_newline
- a: Char
: Bool
(Char/equal a 10)

View File

@ -1,18 +1,21 @@
use Bool/{true,false,or}
use Char/{equal}
is_oper (a: Char) : Bool =
(or (equal 43 a)
(or (equal 45 a)
(or (equal 42 a)
(or (equal 47 a)
(or (equal 37 a)
(or (equal 60 a)
(or (equal 62 a)
(or (equal 61 a)
(or (equal 38 a)
(or (equal 124 a)
(or (equal 94 a)
(or (equal 33 a)
(or (equal 126 a)
false)))))))))))))
is_oper
- a: Char
: Bool
(or (equal 43 a)
(or (equal 45 a)
(or (equal 42 a)
(or (equal 47 a)
(or (equal 37 a)
(or (equal 60 a)
(or (equal 62 a)
(or (equal 61 a)
(or (equal 38 a)
(or (equal 124 a)
(or (equal 94 a)
(or (equal 33 a)
(or (equal 126 a)
false)))))))))))))

View File

@ -1,2 +1,5 @@
is_slash (a: Char) : Bool =
(Char/equal a 47)
is_slash
- a: Char
: Bool
(Char/equal a 47)

View File

@ -1,2 +1,3 @@
eql : Cmp =
~λP λltn λeql λgtn eql
eql : Cmp
~λP λltn λeql λgtn eql

View File

@ -1,2 +1,3 @@
Cmp/gtn : Cmp =
~λP λltn λeql λgtn gtn
Cmp/gtn : Cmp
~λP λltn λeql λgtn gtn

View File

@ -1,9 +1,12 @@
use Bool/{true,false}
use Cmp/{ltn,eql,gtn}
Cmp/is_gtn (cmp: Cmp) : Bool
= match cmp {
ltn: false
eql: false
gtn: true
}
Cmp/is_gtn
- cmp: Cmp
: Bool
match cmp {
ltn: false
eql: false
gtn: true
}

View File

@ -1,2 +1,3 @@
Cmp/ltn : Cmp =
~λP λltn λeql λgtn ltn
Cmp/ltn : Cmp
~λP λltn λeql λgtn ltn

View File

@ -1,8 +1,9 @@
Cmp/match
(P: Cmp -> *)
(l: (P Cmp/ltn))
(e: (P Cmp/eql))
(g: (P Cmp/gtn))
(c: Cmp)
: (P c) =
(~c P l e g)
- P: Cmp -> *
- l: (P Cmp/ltn)
- e: (P Cmp/eql)
- g: (P Cmp/gtn)
- c: Cmp
: (P c)
(~c P l e g)

View File

@ -1,2 +1,6 @@
absurd (e: Empty) (P: *) : P =
(~e λx(P))
absurd
- e: Empty
- P: *
: P
(~e λx(P))

View File

@ -1,4 +1,8 @@
apply <A: *> <B: *> <a: A> <b: B> (f: A -> B) (e: (Equal A a b)) : (Equal B (f a) (f b)) =
match e {
Equal/refl: ~λPλe(e (f e.a))
}: (Equal B (f a) (f b))
apply <A: *> <B: *> <a: A> <b: B>
- f: A -> B
- e: (Equal A a b)
: (Equal B (f a) (f b))
match e {
Equal/refl: ~λPλe(e (f e.a))
}: (Equal B (f a) (f b))

View File

@ -1,6 +1,7 @@
match <T: *> <a: T> <b: T>
(P: ∀(a:T) ∀(b:T) ∀(e: (Equal T a b)) *)
(refl: ∀(x: T) (P x x (Equal/refl T x)))
(e: (Equal T a b))
: (P a b e) =
(~e P refl)
- P: ∀(a:T) ∀(b:T) ∀(e: (Equal T a b)) *
- refl: ∀(x: T) (P x x (Equal/refl T x))
- e: (Equal T a b)
: (P a b e)
(~e P refl)

View File

@ -1,2 +1,5 @@
refl <A> (x: A) : (Equal A x x) =
~ λP λrefl (refl x)
refl <A>
- x: A
: (Equal A x x)
~ λP λrefl (refl x)

View File

@ -1,29 +1,11 @@
bind <A> <B> (a: (IO A)) (b: A -> (IO B)) : (IO B) =
match a {
IO/print: (IO/print B a.text λx (IO/bind A B (a.then x) b))
IO/load: (IO/load B a.file λs (IO/bind A B (a.then s) b))
IO/save: (IO/save B a.file a.text λx (IO/bind A B (a.then Unit/new) b))
IO/done: (b a.term)
}
bind <A> <B>
- a: (IO A)
- b: A -> (IO B)
: (IO B)
//IO/bind
//: ∀(A: *)
//∀(B: *)
//∀(a: (IO A))
//∀(b: ∀(x: A) (IO B))
//(IO B)
//= λA λB λa λb
//use P = λx ∀(b: ∀(x: A) (IO B)) (IO B)
//use print = λtext λthen λb
//(IO/print B text λx (IO/bind A B (then x) b))
//use load = λfile λthen λb
//(IO/load B file λs (IO/bind A B (then s) b))
//use save = λfile λdata λthen λb
//(IO/save
//B
//file
//data
//λx (IO/bind A B (then Unit/one) b)
//)
//use done = λterm λb (b term)
//(~a P print load save done b)
match a {
IO/print: (IO/print B a.text λx (IO/bind A B (a.then x) b))
IO/load: (IO/load B a.file λs (IO/bind A B (a.then s) b))
IO/save: (IO/save B a.file a.text λx (IO/bind A B (a.then Unit/new) b))
IO/done: (b a.term)
}

View File

@ -1,3 +1,4 @@
IO/done
: ∀(A: *) ∀(term: A) (IO A)
= λA λterm ~λP λprint λload λsave λdone (done term)
λA λterm ~λP λprint λload λsave λdone (done term)

View File

@ -3,5 +3,6 @@ IO/load
∀(file: String)
∀(then: ∀(x: String) (IO A))
(IO A)
= λA λfile λthen
~λP λprint λload λsave λdone (load file then)
λA λfile λthen
~λP λprint λload λsave λdone (load file then)

View File

@ -1,9 +1,10 @@
match <A> <B>
(P: (IO A) -> *)
(print: ∀(text: String) ∀(then: ∀(x: Unit) (IO A)) (P (IO/print A text then)))
(load: ∀(file: String) ∀(then: ∀(x: String) (IO A)) (P (IO/load A file then)))
(save: ∀(file: String) ∀(text: String) ∀(then: ∀(x: Unit) (IO A)) (P (IO/save A file text then)))
(done: ∀(term: A) (P (IO/done A term)))
(x: (IO A))
: (P x) =
(~x P print load save done)
- P: (IO A) -> *
- print: ∀(text: String) ∀(then: ∀(x: Unit) (IO A)) (P (IO/print A text then))
- load: ∀(file: String) ∀(then: ∀(x: String) (IO A)) (P (IO/load A file then))
- save: ∀(file: String) ∀(text: String) ∀(then: ∀(x: Unit) (IO A)) (P (IO/save A file text then))
- done: ∀(term: A) (P (IO/done A term))
- x: (IO A)
: (P x)
(~x P print load save done)

View File

@ -1,5 +1,6 @@
IO/print
: ∀(A: *) ∀(text: String) ∀(then: ∀(x: Unit) (IO A))
(IO A)
= λA λtext λthen
~λP λprint λload λsave λdone (print text then)
λA λtext λthen
~λP λprint λload λsave λdone (print text then)

View File

@ -1,20 +1,10 @@
run <A> (x: (IO A)) : (IO A) =
match x {
IO/print: (IO/print A x.text λu (run A (x.then Unit/new)))
IO/load: (IO/load A x.file λs (run A (x.then s)))
IO/save: (IO/save A x.file x.text λu (run A (x.then Unit/new)))
IO/done: (IO/done A x.term)
}
run <A>
- x: (IO A)
: (IO A)
//IO/run
//: ∀(A: *) ∀(x: (IO A)) (IO A)
//= λA λx
//use P = λx (IO A)
//use print = λtext λthen
//(IO/print A text λu (IO/run A (then Unit/new)))
//use load = λfile λthen
//(IO/load A file λs (IO/run A (then s)))
//use save = λfile λtext λthen
//(IO/save A file text λu (IO/run A (then Unit/new)))
//use done = λterm (IO/done A term)
//(~x P print load save done)
match x {
IO/print: (IO/print A x.text λu (run A (x.then Unit/new)))
IO/load: (IO/load A x.file λs (run A (x.then s)))
IO/save: (IO/save A x.file x.text λu (run A (x.then Unit/new)))
IO/done: (IO/done A x.term)
}

View File

@ -4,5 +4,6 @@ IO/save
∀(text: String)
∀(then: ∀(x: Unit) (IO A))
(IO A)
= λA λfile λtext λthen
~λP λprint λload λsave λdone (save file text then)
λA λfile λtext λthen
~λP λprint λload λsave λdone (save file text then)

View File

@ -1,8 +1,11 @@
use List/{cons,nil}
use Bool/{true}
and (list: (List Bool)) : Bool =
fold list {
cons: (Bool/and list.head list.tail)
nil: true
}
and
- list: (List Bool)
: Bool
fold list {
cons: (Bool/and list.head list.tail)
nil: true
}

View File

@ -1,10 +1,13 @@
use List/{cons,nil}
begin <A> (xs: (List A)) : (List A) =
match xs {
cons: match xs.tail {
cons: (cons _ xs.head (begin _ (cons _ xs.tail.head xs.tail.tail)))
nil: (cons _ xs.head (nil _))
}
nil: (nil _)
begin <A>
- xs: (List A)
: (List A)
match xs {
cons: match xs.tail {
cons: (cons _ xs.head (begin _ (cons _ xs.tail.head xs.tail.tail)))
nil: (cons _ xs.head (nil _))
}
nil: (nil _)
}

View File

@ -1,7 +1,11 @@
use List/{cons,nil}
concat <T> (xs: (List T)) (ys: (List T)) : (List T) =
match xs {
cons: (cons _ xs.head (concat _ xs.tail ys))
nil: ys
}
concat <T>
- xs: (List T)
- ys: (List T)
: (List T)
match xs {
cons: (cons _ xs.head (concat _ xs.tail ys))
nil: ys
}

View File

@ -1,2 +1,6 @@
cons <T> (head: T) (tail: (List T)) : (List T) =
~λP λcons λnil (cons head tail)
cons <T>
- head: T
- tail: (List T)
: (List T)
~λP λcons λnil (cons head tail)

View File

@ -1,11 +1,15 @@
use List/{cons,nil}
use Nat/{succ,zero}
drop <A> (n: Nat) (list: (List A)) : (List A) =
match n {
zero: list
succ: match list {
cons: (drop _ n.pred list.tail)
nil: (nil _)
}
drop <A>
- n: Nat
- list: (List A)
: (List A)
match n {
zero: list
succ: match list {
cons: (drop _ n.pred list.tail)
nil: (nil _)
}
}

View File

@ -1,11 +1,15 @@
use List/{cons,nil}
use Bool/{true,false}
filter <A> (cond: A -> Bool) (list: (List A)) : (List A) =
match list {
nil: (nil _)
cons: match result = (cond list.head) {
true: (cons _ list.head (filter _ cond list.tail))
false: (filter _ cond list.tail)
}
filter <A>
- cond: A -> Bool
- list: (List A)
: (List A)
match list {
nil: (nil _)
cons: match result = (cond list.head) {
true: (cons _ list.head (filter _ cond list.tail))
false: (filter _ cond list.tail)
}
}

View File

@ -2,11 +2,15 @@ use Bool/{true,false}
use List/{cons,nil}
use Maybe/{some,none}
find <A> (cond: A -> Bool) (xs: (List A)) : (Maybe A) =
match xs {
cons: match result = (cond xs.head) {
true: (some _ xs.head)
false: (find _ cond xs.tail)
}
nil: (none _)
find <A>
- cond: A -> Bool
- xs: (List A)
: (Maybe A)
match xs {
cons: match result = (cond xs.head) {
true: (some _ xs.head)
false: (find _ cond xs.tail)
}
nil: (none _)
}

View File

@ -1,7 +1,12 @@
use List/{cons,nil}
List/fold <A> (P: *) (c: A -> P -> P) (n: P) (xs: (List A)) : P =
match xs {
cons: (c xs.head (List/fold _ P c n xs.tail))
nil: n
}
List/fold <A> (P: *)
- c: A -> P -> P
- n: P
- xs: (List A)
: P
match xs {
cons: (c xs.head (List/fold _ P c n xs.tail))
nil: n
}

View File

@ -1,8 +1,11 @@
use List/{cons,nil}
use Nat/{succ,zero}
length <A> (xs: (List A)) : Nat =
match xs {
cons: (succ (length _ xs.tail))
nil: zero
}
length <A>
- xs: (List A)
: Nat
match xs {
cons: (succ (length _ xs.tail))
nil: zero
}

View File

@ -1,7 +1,11 @@
use List/{cons,nil}
map <A> <B> (xs: (List A)) (f: A -> B) : (List B) =
fold xs {
cons: (cons _ (f xs.head) xs.tail)
nil: (nil _)
}
map <A> <B>
- xs: (List A)
- fn: A -> B
: (List B)
fold xs {
cons: (cons _ (fn xs.head) xs.tail)
nil: (nil _)
}

View File

@ -1,7 +1,8 @@
match <A>
(P: (List A) -> *)
(c: ∀(head: A) ∀(tail: (List A)) (P (List/cons A head tail)))
(n: (P (List/nil A)))
(xs: (List A))
: (P xs) =
(~xs P c n)
- P: (List A) -> *
- c: ∀(head: A) ∀(tail: (List A)) (P (List/cons A head tail))
- n: (P (List/nil A))
- xs: (List A)
: (P xs)
(~xs P c n)

View File

@ -1,2 +1,4 @@
nil <T> : (List T) =
~λP λcons λnil nil
nil <T>
: (List T)
~λP λcons λnil nil

View File

@ -1,8 +1,11 @@
use List/{cons,nil}
use Bool/{false}
or (list: (List Bool)) : Bool =
fold list {
cons: (Bool/or list.head list.tail)
nil: false
}
or
- list: (List Bool)
: Bool
fold list {
cons: (Bool/or list.head list.tail)
nil: false
}

View File

@ -1,10 +1,17 @@
use List/{cons,nil}
reverse/go <A> (list: (List A)) (result: (List A)) : (List A) =
match list {
nil: result
cons: (reverse/go _ list.tail (cons _ list.head result))
}
reverse/go <A>
- list: (List A)
- result: (List A)
: (List A)
reverse <A> (list: (List A)) : (List A) =
(reverse/go _ list (nil _))
match list {
nil: result
cons: (reverse/go _ list.tail (cons _ list.head result))
}
reverse <A>
- list: (List A)
: (List A)
(reverse/go _ list (nil _))

View File

@ -1,5 +1,8 @@
sum (xs: (List U48)): U48 =
match xs {
++: (+ xs.head (sum xs.tail))
[]: 0
}
sum
- xs: (List U48)
: U48
match xs {
++: (+ xs.head (sum xs.tail))
[]: 0
}

View File

@ -1,11 +1,15 @@
use List/{cons,nil}
use Nat/{succ,zero}
take <A> (n: Nat) (list: (List A)) : (List A) =
match n {
zero: (nil _)
succ: match list {
cons: (cons _ list.head (take _ n.pred list.tail))
nil: (nil _)
}
take <A>
- n: Nat
- list: (List A)
: (List A)
match n {
zero: (nil _)
succ: match list {
cons: (cons _ list.head (take _ n.pred list.tail))
nil: (nil _)
}
}

View File

@ -1,10 +1,14 @@
use List/{cons,nil}
zip <A> <B> (as: (List A)) (bs: (List B)) : (List (Pair A B)) =
match as {
cons: match bs {
cons: (cons _ (Pair/new _ _ as.head bs.head) (zip _ _ as.tail bs.tail))
nil: (nil _)
}
zip <A> <B>
- as: (List A)
- bs: (List B)
: (List (Pair A B))
match as {
cons: match bs {
cons: (cons _ (Pair/new _ _ as.head bs.head) (zip _ _ as.tail bs.tail))
nil: (nil _)
}
nil: (nil _)
}

View File

@ -1,7 +1,11 @@
use Maybe/{some,none}
bind <A> <B> (ma: (Maybe A)) (f: A -> (Maybe B)) : (Maybe B) =
match ma {
some: (f ma.value)
none: (none _)
}
bind <A> <B>
- ma: (Maybe A)
- f: A -> (Maybe B)
: (Maybe B)
match ma {
some: (f ma.value)
none: (none _)
}

View File

@ -1,7 +1,8 @@
match <A>
(P: (Maybe A) -> *)
(s: ∀(value: A) (P (Maybe/some A value)))
(n: (P (Maybe/none A)))
(ma: (Maybe A))
: (P ma) =
(~ma P s n)
- P: (Maybe A) -> *
- s: ∀(value: A) (P (Maybe/some A value))
- n: (P (Maybe/none A))
- ma: (Maybe A)
: (P ma)
(~ma P s n)

View File

@ -1,2 +1,4 @@
Maybe/monad : (Monad Maybe) =
(Monad/new _ Maybe/bind Maybe/pure)
Maybe/monad
: (Monad Maybe)
(Monad/new _ Maybe/bind Maybe/pure)

View File

@ -1,2 +1,4 @@
none <T> : (Maybe T) =
~λP λsome λnone none
none <T>
: (Maybe T)
~λP λsome λnone none

View File

@ -1,2 +1,5 @@
pure <T> (x: T) : (Maybe T) =
(Maybe/some _ x)
pure <T>
- x: T
: (Maybe T)
(Maybe/some _ x)

View File

@ -1,2 +1,5 @@
some <T> (value: T) : (Maybe T) =
~λP λsome λnone (some value)
some <T>
- value: T
: (Maybe T)
~λP λsome λnone (some value)

View File

@ -3,6 +3,7 @@ new
∀(bind: ∀(A: *) ∀(B: *) ∀(a: (M A)) ∀(b: ∀(a: A) (M B)) (M B))
∀(pure: ∀(A: *) ∀(a: A) (M A))
(Monad M)
= λM λbind λpure
~λP λnew
(new bind pure)
λM λbind λpure
~λP λnew
(new bind pure)

View File

@ -1,7 +1,11 @@
use Nat/{succ,zero}
add (a: Nat) (b: Nat) : Nat =
match a {
succ: (succ (add a.pred a))
zero: b
}
add
- a: Nat
- b: Nat
: Nat
match a {
succ: (succ (add a.pred b))
zero: b
}

View File

@ -1,7 +1,10 @@
use Nat/{succ,zero}
double (n: Nat) : Nat =
match n {
zero: zero
succ: (succ (succ (double n.pred)))
}
double
- n: Nat
: Nat
match n {
zero: zero
succ: (succ (succ (double n.pred)))
}

View File

@ -1,14 +1,18 @@
use Nat/{succ,zero}
use Bool/{true,false}
equal (a: Nat) (b: Nat) : Bool =
match a with (b: Nat) {
succ: match b {
succ: (equal a.pred b.pred)
zero: false
}
zero: match b {
succ: false
zero: true
}
equal
- a: Nat
- b: Nat
: Bool
match a with (b: Nat) {
succ: match b {
succ: (equal a.pred b.pred)
zero: false
}
zero: match b {
succ: false
zero: true
}
}

View File

@ -1,10 +1,13 @@
use Nat/{succ,zero}
half (n: Nat) : Nat =
match n {
succ: match n.pred {
succ: (succ (half n.pred.pred))
zero: zero
}
half
- n: Nat
: Nat
match n {
succ: match n.pred {
succ: (succ (half n.pred.pred))
zero: zero
}
zero: zero
}

View File

@ -1,11 +1,15 @@
use Nat/{succ,zero}
use Bool/{true,false}
is_gtn (a: Nat) (b: Nat) : Bool =
match a with (b: Nat) {
zero: false
succ: match b {
zero: true
succ: (is_gtn a.pred b.pred)
}
is_gtn
- a: Nat
- b: Nat
: Bool
match a with (b: Nat) {
zero: false
succ: match b {
zero: true
succ: (is_gtn a.pred b.pred)
}
}

View File

@ -1,14 +1,18 @@
use Nat/{succ,zero}
use Bool/{true,false}
is_ltn (a: Nat) (b: Nat) : Bool =
match a with (b: Nat) {
zero: match b {
zero: false
succ: true
}
succ: match b {
zero: false
succ: (is_ltn a.pred b.pred)
}
is_ltn
- a: Nat
- b: Nat
: Bool
match a with (b: Nat) {
zero: match b {
zero: false
succ: true
}
succ: match b {
zero: false
succ: (is_ltn a.pred b.pred)
}
}

View File

@ -1,8 +1,12 @@
use Nat/{succ,zero}
use Bool/{true,false}
is_ltn_or_eql (a: Nat) (b: Nat) : Bool =
match is_lt = (Nat/is_ltn a b) {
true: true
false: (Nat/equal a b)
}
is_ltn_or_eql
- a: Nat
- b: Nat
: Bool
match is_lt = (Nat/is_ltn a b) {
true: true
false: (Nat/equal a b)
}

View File

@ -1,8 +1,11 @@
use Nat/{zero,succ}
use Bool/{true,false}
is_zero (n: Nat) : Bool =
match n {
zero: true
succ: false
}
is_zero
- n: Nat
: Bool
match n {
zero: true
succ: false
}

View File

@ -1,8 +1,8 @@
match
(P: Nat -> *)
(s: ∀(pred: Nat) (P (Nat/succ pred)))
(z: (P Nat/zero))
(n: Nat)
: (P n) =
(~n P s z)
- P: Nat -> *
- s: ∀(pred: Nat) (P (Nat/succ pred))
- z: (P Nat/zero)
- n: Nat
: (P n)
(~n P s z)

View File

@ -1,7 +1,11 @@
use Nat/{succ,zero}
mul (a: Nat) (b: Nat) : Nat =
match b {
succ: (Nat/add a (Nat/mul a b.pred))
zero: zero
}
mul
- a: Nat
- b: Nat
: Nat
match b {
succ: (Nat/add a (Nat/mul a b.pred))
zero: zero
}

View File

@ -1,2 +1,5 @@
succ (n: Nat) : Nat =
~λP λsucc λzero (succ n)
succ
- n: Nat
: Nat
~λP λsucc λzero (succ n)

View File

@ -1,2 +1,4 @@
zero : Nat =
~λP λsucc λzero zero
zero
: Nat
~λP λsucc λzero zero

View File

@ -1,8 +1,12 @@
use Parser/Result/{done,fail}
bind <A> <B> (pa: (Parser A)) (f: A -> (Parser B)) : (Parser B) =
λcode
match result = (pa code) {
done: (f result.value result.code)
fail: (fail _ result.error)
}
bind <A> <B>
- pa: (Parser A)
- f: A -> (Parser B)
: (Parser B)
λcode
match result = (pa code) {
done: (f result.value result.code)
fail: (fail _ result.error)
}

View File

@ -1,9 +1,11 @@
use Parser/Result/{done,fail}
use List/{cons,nil}
char : (Parser Char) =
λcode
match code {
cons: (done _ code.tail code.head)
nil: (fail _ "eof")
}
char
: (Parser Char)
λcode
match code {
cons: (done _ code.tail code.head)
nil: (fail _ "eof")
}

View File

@ -1,5 +1,7 @@
use Char/{is_decimal}
use Parser/pick_while
decimal : (Parser String) =
(pick_while is_decimal)
decimal
: (Parser String)
(pick_while is_decimal)

View File

@ -1,2 +1,5 @@
fail <A> (error: String) : (Parser A) =
λcode (Parser/Result/fail _ error)
fail <A>
- error: String
: (Parser A)
λcode (Parser/Result/fail _ error)

View File

@ -2,9 +2,11 @@ use Parser/Result/{done}
use Bool/{true,false}
use List/{cons,nil}
is_eof : (Parser Bool) =
λcode
match code {
cons: (done _ code false)
nil: (done _ (nil _) true)
}
is_eof
: (Parser Bool)
λcode
match code {
cons: (done _ code false)
nil: (done _ (nil _) true)
}

View File

@ -1,8 +1,12 @@
use Parser/Result/{done,fail}
map <A> <B> (f: A -> B) (p: (Parser A)) : (Parser B) =
λcode
match result = (p code) {
done: (done _ result.code (f result.value))
fail: (fail _ result.error)
}
map <A> <B>
- f: A -> B
- p: (Parser A)
: (Parser B)
λcode
match result = (p code) {
done: (done _ result.code (f result.value))
fail: (fail _ result.error)
}

View File

@ -1,5 +1,7 @@
use Char/{is_name}
use Parser/pick_while
name : (Parser String) =
(pick_while is_name)
name
: (Parser String)
(pick_while is_name)

View File

@ -1,5 +1,7 @@
use Char/{is_oper}
use Parser/pick_while
oper : (Parser String) =
(pick_while is_oper)
oper
: (Parser String)
(pick_while is_oper)

View File

@ -1,9 +1,11 @@
use Parser/Result/{done,fail}
use List/{cons,nil}
pick : (Parser Char) =
λcode
match code {
cons: (done _ code.tail code.head)
nil: (fail _ "empty")
}
pick
: (Parser Char)
λcode
match code {
cons: (done _ code.tail code.head)
nil: (fail _ "empty")
}

View File

@ -1,2 +1,5 @@
pure <A> (value: A) : (Parser A) =
λcode (Parser/Result/done _ code value)
pure <A>
- value: A
: (Parser A)
λcode (Parser/Result/done _ code value)

View File

@ -3,11 +3,15 @@ use Parser/pure
use List/{cons,nil}
use Nat/{succ,zero}
repeat <A> (n: Nat) (p: (Parser A)) : (Parser (List A)) =
match n {
zero: (pure _ (nil _))
succ:
(bind _ _ p (λhead
(bind _ _ (repeat _ n.pred p) (λtail
(pure _ (cons _ head tail))))))
}
repeat <A>
- n: Nat
- p: (Parser A)
: (Parser (List A))
match n {
zero: (pure _ (nil _))
succ:
(bind _ _ p (λhead
(bind _ _ (repeat _ n.pred p) (λtail
(pure _ (cons _ head tail))))))
}

View File

@ -1,2 +1,5 @@
skip <A> (parser: (Parser A)) : (Parser A) =
λcode (parser code)
skip <A>
- parser: (Parser A)
: (Parser A)
λcode (parser code)

View File

@ -1,5 +1,8 @@
use Parser/repeat
use Parser/char
take (n: Nat) : (Parser String) =
(repeat _ n char)
take
- n: Nat
: (Parser String)
(repeat _ n char)

View File

@ -5,22 +5,24 @@ use Parser/Result/{done,fail}
use Bool/{true,false}
use Char/{equal}
test (test_str: String) : (Parser Bool) =
λcode
match test_str {
cons:
match code {
cons:
match eq = (equal test_str.head code.head) {
true:
match result = (test test_str.tail code.tail) {
done: (done _ code result.value)
fail: (fail _ result.error)
}
false: (done _ code false)
}
nil: (done _ code false)
}
nil: (done _ code true)
}
test
- test_str: String
: (Parser Bool)
λcode
match test_str {
cons:
match code {
cons:
match eq = (equal test_str.head code.head) {
true:
match result = (test test_str.tail code.tail) {
done: (done _ code result.value)
fail: (fail _ result.error)
}
false: (done _ code false)
}
nil: (done _ code false)
}
nil: (done _ code true)
}

View File

@ -7,14 +7,17 @@ use Parser/fail
use Bool/{true,false}
use String/{length}
text (txt: String) : (Parser Unit) =
(skip _
(bind _ _ (test txt) λsuccess
match success {
true:
(bind _ _ (take (length txt)) λx
(pure _ Unit/new))
false: (fail _ "Text mismatch")
}
)
text
- txt: String
: (Parser Unit)
(skip _
(bind _ _ (test txt) λsuccess
match success {
true:
(bind _ _ (take (length txt)) λx
(pure _ Unit/new))
false: (fail _ "Text mismatch")
}
)
)

View File

@ -1,5 +1,9 @@
use Parser/until/go
use List/{nil}
until <A> (until: (Parser Bool)) (parse: (Parser A)) : (Parser (List A)) =
(go _ until parse (nil _))
until <A>
- until: (Parser Bool)
- parse: (Parser A)
: (Parser (List A))
(go _ until parse (nil _))

View File

@ -4,13 +4,16 @@ use Parser/bind
use Parser/fail
use Bool/{true,false}
variant <A> (variants: (List (Parser/Guard A))) : (Parser A) =
match variants {
cons:
(bind _ _ (fst _ _ variants.head) λsuccess
match success {
true: (snd _ _ variants.head)
false: (variant _ variants.tail)
})
nil: (fail _ "No matching variant")
}
variant <A>
- variants: (List (Parser/Guard A))
: (Parser A)
match variants {
cons:
(bind _ _ (fst _ _ variants.head) λsuccess
match success {
true: (snd _ _ variants.head)
false: (variant _ variants.tail)
})
nil: (fail _ "No matching variant")
}

View File

@ -1,4 +1,5 @@
Sigma/new
: ∀(A: *) ∀(B: ∀(x: A) *) ∀(a: A) ∀(b: (B a))
(Sigma A B)
= λA λB λa λb ~λP λnew (new a b)
λA λB λa λb ~λP λnew (new a b)

View File

@ -1,11 +1,14 @@
use List/{cons,nil}
begin (str: (List Char)) : (List Char) =
match str {
cons:
match str.tail {
cons: (cons _ str.head (begin str.tail))
nil: str
}
nil: str
}
begin
- str: (List Char)
: (List Char)
match str {
cons:
match str.tail {
cons: (cons _ str.head (begin str.tail))
nil: str
}
nil: str
}

View File

@ -1,20 +1,21 @@
String/cmp
: ∀(a: String) ∀(b: String) Cmp
= λa λb
use P = λx ∀(b: String) Cmp
use cons = λa.head λa.tail λb
use P = λx ∀(a.head: Char) ∀(a.tail: String) Cmp
use cons = λb.head λb.tail λa.head λa.tail
use P = λx Cmp
use ltn = Cmp/ltn
use eql = (cmp a.tail b.tail)
use gtn = Cmp/gtn
(~(U48/cmp a.head b.head) P ltn eql gtn)
use nil = λa.head λa.tail Cmp/gtn
(~b P cons nil a.head a.tail)
use nil = λb
λa λb
use P = λx ∀(b: String) Cmp
use cons = λa.head λa.tail λb
use P = λx ∀(a.head: Char) ∀(a.tail: String) Cmp
use cons = λb.head λb.tail λa.head λa.tail
use P = λx Cmp
use cons = λb.head λb.tail Cmp/ltn
use nil = Cmp/eql
(~b P cons nil)
(~a P cons nil b)
use ltn = Cmp/ltn
use eql = (cmp a.tail b.tail)
use gtn = Cmp/gtn
(~(U48/cmp a.head b.head) P ltn eql gtn)
use nil = λa.head λa.tail Cmp/gtn
(~b P cons nil a.head a.tail)
use nil = λb
use P = λx Cmp
use cons = λb.head λb.tail Cmp/ltn
use nil = Cmp/eql
(~b P cons nil)
(~a P cons nil b)

View File

@ -1,4 +1,8 @@
use List/{concat}
concat (xs: (List Char)) (ys: (List Char)) : (List Char) =
(concat xs ys)
concat
- xs: (List Char)
- ys: (List Char)
: (List Char)
(concat xs ys)

View File

@ -1,2 +1,6 @@
String/cons (head: Char) (tail: String) : String =
~λP λcons λnil (cons head tail)
String/cons
- head: Char
- tail: String
: String
~λP λcons λnil (cons head tail)

View File

@ -1,17 +1,21 @@
String/equal (a: String) (b: String) : Bool =
use P = λx ∀(b: String) Bool
use cons = λa.head λa.tail λb
use P = λx ∀(a.head: Char) ∀(a.tail: String) Bool
use cons = λb.head λb.tail λa.head λa.tail
(Bool/and
(U48/equal a.head b.head)
(String/equal a.tail b.tail)
)
use nil = λa.head λa.tail Bool/false
(~b P cons nil a.head a.tail)
use nil = λb
use P = λx Bool
use cons = λb.head λb.tail Bool/false
use nil = Bool/true
(~b P cons nil)
(~a P cons nil b)
String/equal
- a: String
- b: String
: Bool
use P = λx ∀(b: String) Bool
use cons = λa.head λa.tail λb
use P = λx ∀(a.head: Char) ∀(a.tail: String) Bool
use cons = λb.head λb.tail λa.head λa.tail
(Bool/and
(U48/equal a.head b.head)
(String/equal a.tail b.tail)
)
use nil = λa.head λa.tail Bool/false
(~b P cons nil a.head a.tail)
use nil = λb
use P = λx Bool
use cons = λb.head λb.tail Bool/false
use nil = Bool/true
(~b P cons nil)
(~a P cons nil b)

View File

@ -1,7 +1,8 @@
indent
: ∀(tab: Nat) String
= λtab
use P = λx String
use succ = λtab.pred (String/cons 32 (String/cons 32 (indent tab.pred)))
use zero = String/nil
(~tab P succ zero)
λtab
use P = λx String
use succ = λtab.pred (String/cons 32 (String/cons 32 (indent tab.pred)))
use zero = String/nil
(~tab P succ zero)

View File

@ -1,15 +1,9 @@
join (sep: String) (strs: (List String)) : String =
match strs {
List/cons: (String/concat strs.head (String/join/go sep strs.tail))
List/nil: String/nil
}
join
- sep: String
- strs: (List String)
: String
//join
//: ∀(sep: String) ∀(strs: (List String)) String
//= λsep λstrs
//use P = λx String
//use cons = λh λt (String/concat h (String/join/go sep t))
//use nil = String/nil
//(~strs P cons nil)
match strs {
List/cons: (String/concat strs.head (String/join/go sep strs.tail))
List/nil: String/nil
}

View File

@ -1,4 +1,7 @@
use List/{length}
length (s: (List Char)) : Nat =
(length s)
length
- s: (List Char)
: Nat
(length s)

View File

@ -1,3 +1,4 @@
newline
: String
= (String/cons 10 String/nil)
(String/cons 10 String/nil)

View File

@ -1,2 +1,4 @@
String/nil : String =
~λP λcons λnil nil
String/nil
: String
~λP λcons λnil nil

View File

@ -1,4 +1,6 @@
use List/{cons,nil}
quote : (List Char) =
(cons _ '"' (nil _))
quote
: (List Char)
(cons _ '"' (nil _))

View File

@ -1,23 +1,24 @@
skip
: ∀(str: String) String
= λstr
use P = λx String
use cons = λc0 λcs
λstr
use P = λx String
use cons = λc0 λcs
use P = λx ∀(c0: Char) ∀(cs: String) String
use true = λc0 λcs (String/skip cs)
use false = λc0 λcs
use P = λx ∀(c0: Char) ∀(cs: String) String
use true = λc0 λcs (String/skip cs)
use false = λc0 λcs
use P = λx ∀(c0: Char) ∀(cs: String) String
use true = λc0 λcs
use P = λx ∀(c0: Char) String
use cons = λc1 λcs λc0
use P = λx ∀(c0: Char) ∀(c1: Char) ∀(cs: String) String
use true = λc0 λc1 λcs (String/skip/comment cs)
use false = λc0 λc1 λcs (String/cons c0 (String/cons c1 cs))
(~(Char/is_slash c1) P true false c0 c1 cs)
use nil = λc0 (String/cons c0 String/nil)
(~cs P cons nil c0)
use false = λc0 λcs (String/cons c0 cs)
(~(Char/is_slash c0) P true false c0 cs)
(~(Char/is_blank c0) P true false c0 cs)
use nil = String/nil
(~str P cons nil)
use true = λc0 λcs
use P = λx ∀(c0: Char) String
use cons = λc1 λcs λc0
use P = λx ∀(c0: Char) ∀(c1: Char) ∀(cs: String) String
use true = λc0 λc1 λcs (String/skip/comment cs)
use false = λc0 λc1 λcs (String/cons c0 (String/cons c1 cs))
(~(Char/is_slash c1) P true false c0 c1 cs)
use nil = λc0 (String/cons c0 String/nil)
(~cs P cons nil c0)
use false = λc0 λcs (String/cons c0 cs)
(~(Char/is_slash c0) P true false c0 cs)
(~(Char/is_blank c0) P true false c0 cs)
use nil = String/nil
(~str P cons nil)

Some files were not shown because too many files have changed in this diff Show More