-
Notifications
You must be signed in to change notification settings - Fork 0
/
example4
24 lines (16 loc) · 1.04 KB
/
example4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let F = λ(r : Type) → < Nil | Cons : { head : Integer, tail : r } >
let ListInt = ∀(r : Type) → (F r → r) → r
let nil : ListInt = λ(r : Type) → λ(frr : F r → r) →
frr (F r).Nil
let cons: Integer → ListInt → ListInt = λ(head : Integer) → λ(tail : ListInt) →
λ(r : Type) → λ(frr : F r → r) →
let fr = (F r).Cons { head = head, tail = tail r frr }
in frr fr
let foldLeft : ∀(r : Type) → ∀(init : r) → ∀(update : r → Integer → r) → ListInt → r =
λ(r : Type) → λ(init : r) → λ(update : r → Integer → r) → λ(list : ListInt) →
let consR : { head : Integer, tail : r } → r = λ(fr : { head : Integer, tail : r }) → update fr.tail fr.head
let frr : F r → r = λ(fr : F r) → merge { Nil = init, Cons = consR } fr
in list r frr
let toList : ListInt → List Integer = λ(list : ListInt) →
foldLeft (List Integer) ([]: List Integer) (λ(r : List Integer) → λ(x: Integer) → r # [ x ]) list
in toList (cons +456 (cons -123 nil))