list test

This commit is contained in:
Jonas Maier 2024-12-17 12:32:57 +01:00
parent d3f449c17f
commit c430bf3733
Signed by: jonas
SSH Key Fingerprint: SHA256:yRTjlpb3jSdw2EnZLAWyB4AghBPI8tu42eFXiICyb1U
2 changed files with 28 additions and 13 deletions

View File

@ -1,7 +1,18 @@
type list = FOR b,a[(a --> b --> a) --> a --> a] in
let emptyList: list = (for b,a[fun (h: (a --> b --> a), i: a) { i }]) in
let cons: FOR b [list<b> --> b --> list<b>] = for b [fun (x: list<b>, e: b) { for a [fun(f: (a --> b --> a), i: a) { f (x<a> f i) e }]}] in
let cons: FOR b [b --> list<b> --> list<b>] = for b [fun (e: b, x: list<b>) { for a [fun(f: (a --> b --> a), i: a) { f (x<a> f i) e }]}] in
let foldr: FOR b [list<b> --> list<b>] = for b [fun (l: list<b>) {l}] in
let len: FOR b [list<b> --> int] = for b [fun (ls: list<b>) { ls<int> (fun (x: int, y: b) { plus 1 x }) 0 } ] in
let map: FOR a,b [(a --> b) --> list<a> --> list<b>] =
for a,b [
fun (f: (a --> b), as: list<a>): list<b> {
as<list<b>> (fun (bs: list<b>, e: a) { cons<b> (f e) bs }) (emptyList<b>)
}
] in
let sum: (list<int> --> int) = fun (ls: list<int>) { ls <int> fun (a: int, b: int) {plus a b} 0 } in
sum (cons<int> (cons<int> (cons<int> (emptyList<int>) 2) 3) 99);
let ci: (int --> list<int> --> list<int>) = cons<int> in
let eli: list<int> = emptyList<int> in
let foo: list<int> = (ci 3 (ci 2 (ci 1 (eli)))) in
let double: (int --> int) = fun (x: int) { plus x x } in
let bar: list<int> = map<int><int> double foo in
sum bar;

View File

@ -178,19 +178,23 @@ well_typed!(
well_typed!(lists_2, "for b [fun(x: FOR a[(a --> b)]){x<b>}]");
/*
well_typed!(lists_3, "
type list = FOR b,a[(a --> b --> a) --> a --> a] in
let emptyList: list = (for b,a[fun (h: (a --> b --> a), i: a) { i }]) in
let cons: FOR b [list<b> --> b --> list<b>] = for b [fun (x: list<b>, e: b) { for a [fun(f: (a --> b --> a), i: a) { f (x<a> f i) e }]}] in
let foldr: FOR b [list<b> --> list<b>] = for b [fun (l: list<b>) {l}] in
let len: FOR b [list<b> --> int] = for b [fun (ls: list<b>) { ls<int> (fun (x: int, y: b) { plus 1 x }) 0 } ] in
len<int> (cons<int> (cons<int> (emptyList<int>) 0) 0);
type list = FOR b,a[(a --> b --> a) --> a --> a] in
let emptyList: list = (for b,a[fun (h: (a --> b --> a), i: a) { i }]) in
let cons: FOR b [list<b> --> b --> list<b>] = for b [fun (x: list<b>, e: b) { for a [fun(f: (a --> b --> a), i: a) { f (x<a> f i) e }]}] in
let cons: FOR b [b --> list<b> --> list<b>] = for b [fun (e: b, x: list<b>) { for a [fun(f: (a --> b --> a), i: a) { f (x<a> f i) e }]}] in
let foldr: FOR b [list<b> --> list<b>] = for b [fun (l: list<b>) {l}] in
let len: FOR b [list<b> --> int] = for b [fun (ls: list<b>) { ls<int> (fun (x: int, y: b) { plus 1 x }) 0 } ] in
let map: FOR a,b [(a --> b) --> list<a> --> list<b>] =
for a,b [
fun (f: (a --> b), as: list<a>): list<b> {
as<list<b>> (fun (bs: list<b>, e: a) { cons<b> (f e) bs }) (emptyList<b>)
}
] in
let sum: (list<int> --> int) = fun (ls: list<int>) { ls <int> fun (a: int, b: int) {plus a b} 0 } in
sum (cons<int> (cons<int> (emptyList<int>) 2) 3);
*/
let ci: (int --> list<int> --> list<int>) = cons<int> in
let eli: list<int> = emptyList<int> in
let foo: list<int> = (ci 3 (ci 2 (ci 1 (eli)))) in
let double: (int --> int) = fun (x: int) { plus x x } in
let bar: list<int> = map<int><int> double foo in
sum bar
");