Make the sample programs actually run.

This commit is contained in:
Danila Fedorin 2019-06-12 08:53:54 -07:00
parent c3d4ef22ce
commit 396043d801
4 changed files with 18 additions and 2 deletions

View File

@ -1,2 +0,0 @@
data Bool = { True, False }
data IntList = { Nil, Cons(Int, IntList) }

View File

@ -1,6 +1,8 @@
data IntList = { Nil, Cons(Int, IntList) }
defn length l = { defn length l = {
case l of { case l of {
Nil -> { 0 } Nil -> { 0 }
Cons(x, xs) -> { 1 + length xs } Cons(x, xs) -> { 1 + length xs }
} }
} }
defn main = { length (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))) }

View File

@ -1,6 +1,14 @@
data Bool = { True, False }
defn not b = { defn not b = {
case b of { case b of {
False -> { True } False -> { True }
True -> { False } True -> { False }
} }
} }
defn booli b = {
case b of {
False -> { 0 }
True -> { 1 }
}
}
defn main = { booli (not False) }

8
programs/sum.lily Normal file
View File

@ -0,0 +1,8 @@
data IntList = { Nil, Cons(Int, IntList) }
defn sum l = {
case l of {
Nil -> { 0 }
Cons(x, xs) -> { x + sum xs }
}
}
defn main = { sum (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))) }