diff --git a/programs/data_decls.lily b/programs/data_decls.lily deleted file mode 100644 index 85af0c1..0000000 --- a/programs/data_decls.lily +++ /dev/null @@ -1,2 +0,0 @@ -data Bool = { True, False } -data IntList = { Nil, Cons(Int, IntList) } diff --git a/programs/length.lily b/programs/length.lily index 3463966..1b77d70 100644 --- a/programs/length.lily +++ b/programs/length.lily @@ -1,6 +1,8 @@ +data IntList = { Nil, Cons(Int, IntList) } defn length l = { case l of { Nil -> { 0 } Cons(x, xs) -> { 1 + length xs } } } +defn main = { length (Cons 1 (Cons 2 (Cons 3 (Cons 4 Nil)))) } diff --git a/programs/not.lily b/programs/not.lily index 8676963..7b2bf4b 100644 --- a/programs/not.lily +++ b/programs/not.lily @@ -1,6 +1,14 @@ +data Bool = { True, False } defn not b = { case b of { False -> { True } True -> { False } } } +defn booli b = { + case b of { + False -> { 0 } + True -> { 1 } + } +} +defn main = { booli (not False) } diff --git a/programs/sum.lily b/programs/sum.lily new file mode 100644 index 0000000..9113539 --- /dev/null +++ b/programs/sum.lily @@ -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)))) }