Add closures and fix lets in monomorphizer
This commit is contained in:
parent
677a200a15
commit
72e599d5de
26 changed files with 1440 additions and 692 deletions
6
sample-programs/working/addition.chrf
Normal file
6
sample-programs/working/addition.chrf
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
|
||||
add : Int -> Int -> Int -> Int
|
||||
add x y z = x + y + z
|
||||
|
||||
main = add 8 6 2
|
||||
7
sample-programs/working/apply.crf
Normal file
7
sample-programs/working/apply.crf
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
|
||||
|
||||
apply : (Int -> Int) -> Int -> Int
|
||||
apply f y = f y
|
||||
|
||||
main = apply (\y. y + y) 5
|
||||
10
sample-programs/working/closure.crf
Normal file
10
sample-programs/working/closure.crf
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
|
||||
|
||||
|
||||
|
||||
apply : (Int -> Int) -> Int -> Int
|
||||
apply f z = f z
|
||||
|
||||
main =
|
||||
let x = 10 in
|
||||
apply (\y. y + x) 6
|
||||
15
sample-programs/working/foldr.crf
Normal file
15
sample-programs/working/foldr.crf
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
data List a where
|
||||
Nil : List a
|
||||
Cons : a -> List a -> List a
|
||||
|
||||
foldr : (a -> b -> b) -> b -> List a -> b
|
||||
foldr f y xs = case xs of
|
||||
Nil => y
|
||||
Cons x xs => f x (foldr f y xs)
|
||||
|
||||
|
||||
main = let z = 2 in foldr (\x.\y. x + y + z) 0 (Cons 1000 (Cons 100 Nil))
|
||||
|
||||
|
||||
|
||||
25
sample-programs/working/lambda-2.crf
Normal file
25
sample-programs/working/lambda-2.crf
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
data List (a) where
|
||||
Nil : List (a)
|
||||
Cons : a -> List (a) -> List (a)
|
||||
|
||||
map : (a -> b) -> List (a) -> List (b)
|
||||
map f xs = case xs of
|
||||
Nil => Nil
|
||||
Cons x xs => Cons (f x) (map f xs)
|
||||
|
||||
add : Int -> Int -> Int
|
||||
add x y = x + y
|
||||
|
||||
foldr : (a -> b -> b) -> b -> List (a) -> b
|
||||
foldr f y xs = case xs of
|
||||
Nil => y
|
||||
Cons x xs => f x (foldr f y xs)
|
||||
|
||||
f : List (Int)
|
||||
f = ((\x.\ys. map (\y. add y x) ys) 4 (Cons 1 (Cons 2 Nil)))
|
||||
-- [5, 6]
|
||||
|
||||
main : Int
|
||||
main = foldr add 0 f
|
||||
|
||||
|
||||
21
sample-programs/working/lambda.crf
Normal file
21
sample-programs/working/lambda.crf
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
data List a where
|
||||
Nil : List a
|
||||
Cons : a -> List a -> List a
|
||||
|
||||
map : (a -> b) -> List a -> List b
|
||||
map f xs = case xs of
|
||||
Nil => Nil
|
||||
Cons x xs => Cons (f x) (map f xs)
|
||||
|
||||
|
||||
f : List Int
|
||||
f = (\x.\ys. map (\y. y + x) ys) 4 (Cons 1 (Cons 2 Nil))
|
||||
-- [5, 6]
|
||||
|
||||
sum : List Int -> Int
|
||||
sum xs = case xs of
|
||||
Nil => 0
|
||||
Cons x xs => x + sum xs
|
||||
|
||||
main = sum f
|
||||
|
||||
3
sample-programs/working/let.crf
Normal file
3
sample-programs/working/let.crf
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
|
||||
main = let x = 10 in 6 + x
|
||||
16
sample-programs/working/map.crf
Normal file
16
sample-programs/working/map.crf
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
data List a where
|
||||
Nil : List a
|
||||
Cons : a -> List a -> List a
|
||||
|
||||
map : (a -> b) -> List a -> List b
|
||||
map f xs = case xs of
|
||||
Nil => Nil
|
||||
Cons x xs => Cons (f x) (map f xs)
|
||||
|
||||
sum : List Int -> Int
|
||||
sum xs = case xs of
|
||||
Nil => 0
|
||||
Cons x xs => x + (sum xs)
|
||||
|
||||
main = let y = 10 in sum (map (\x. x + y) (Cons 2 (Cons 4 Nil)))
|
||||
7
sample-programs/working/simple.crf
Normal file
7
sample-programs/working/simple.crf
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
|
||||
|
||||
f = 10
|
||||
|
||||
|
||||
main = f + 6
|
||||
Loading…
Add table
Add a link
Reference in a new issue