Add closures and fix lets in monomorphizer

This commit is contained in:
Martin Fredin 2023-05-06 22:49:08 +02:00
parent 677a200a15
commit 72e599d5de
26 changed files with 1440 additions and 692 deletions

View 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