From 76478dd79705313860c00008cee75c48db814ecc Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sun, 13 May 2018 21:12:57 +0200 Subject: Add examples --- bad/appType.mim | 1 + bad/divideBy0.mim | 2 ++ bad/headOfNil.mim | 1 + bad/ifType.mim | 3 +++ bad/outOfTupleBounds.mim | 4 ++++ bad/tailOfNil.mim | 1 + good/concat.mim | 7 +++++++ good/curry.mim | 8 ++++++++ good/eachToEach.mim | 24 ++++++++++++++++++++++++ good/factorial.mim | 5 +++++ good/fib.mim | 7 +++++++ good/partial.mim | 5 +++++ good/simplify.mim | 23 +++++++++++++++++++++++ good/tupleAdd.mim | 4 ++++ 14 files changed, 95 insertions(+) create mode 100644 bad/appType.mim create mode 100644 bad/divideBy0.mim create mode 100644 bad/headOfNil.mim create mode 100644 bad/ifType.mim create mode 100644 bad/outOfTupleBounds.mim create mode 100644 bad/tailOfNil.mim create mode 100644 good/concat.mim create mode 100644 good/curry.mim create mode 100644 good/eachToEach.mim create mode 100644 good/factorial.mim create mode 100644 good/fib.mim create mode 100644 good/partial.mim create mode 100644 good/simplify.mim create mode 100644 good/tupleAdd.mim diff --git a/bad/appType.mim b/bad/appType.mim new file mode 100644 index 0000000..d3d9eba --- /dev/null +++ b/bad/appType.mim @@ -0,0 +1 @@ +((lambda x : Int x) false) diff --git a/bad/divideBy0.mim b/bad/divideBy0.mim new file mode 100644 index 0000000..0fc6dc2 --- /dev/null +++ b/bad/divideBy0.mim @@ -0,0 +1,2 @@ +; to jeszcze nie dziaƂa +(/ 3 0) diff --git a/bad/headOfNil.mim b/bad/headOfNil.mim new file mode 100644 index 0000000..c74b3d7 --- /dev/null +++ b/bad/headOfNil.mim @@ -0,0 +1 @@ +(head nil : [Int]) diff --git a/bad/ifType.mim b/bad/ifType.mim new file mode 100644 index 0000000..dea4393 --- /dev/null +++ b/bad/ifType.mim @@ -0,0 +1,3 @@ +(if true + 1 + false) diff --git a/bad/outOfTupleBounds.mim b/bad/outOfTupleBounds.mim new file mode 100644 index 0000000..9069ea6 --- /dev/null +++ b/bad/outOfTupleBounds.mim @@ -0,0 +1,4 @@ +; tuples are indexed from 1 +; we know the tuple's size during typechecking, so this is a static typechecking +; error +{1 2 3}.4 diff --git a/bad/tailOfNil.mim b/bad/tailOfNil.mim new file mode 100644 index 0000000..908b114 --- /dev/null +++ b/bad/tailOfNil.mim @@ -0,0 +1 @@ +(tail nil : [Int]) diff --git a/good/concat.mim b/good/concat.mim new file mode 100644 index 0000000..192da56 --- /dev/null +++ b/good/concat.mim @@ -0,0 +1,7 @@ +(letrec (concatN : [Int] -> [Int] -> [Int] l1 : [Int] l2 : [Int]) + (if (isnil l1) + l2 + (let (h) (head l1) + (let (t) (tail l1) + (cons h (concatN t l2))))) + (concatN (cons 2 nil : [Int]) (cons 1 nil : [Int]))) diff --git a/good/curry.mim b/good/curry.mim new file mode 100644 index 0000000..2fc0b7b --- /dev/null +++ b/good/curry.mim @@ -0,0 +1,8 @@ +(let (curry f : {Int Int} -> Int) + (lambda n : Int + (lambda m : Int + (f {n m}))) +(let (add xy : {Int Int}) + (+ xy.1 xy.2) +(let (cAdd) (curry add) + ((cAdd 3) 4)))) diff --git a/good/eachToEach.mim b/good/eachToEach.mim new file mode 100644 index 0000000..1bc7f05 --- /dev/null +++ b/good/eachToEach.mim @@ -0,0 +1,24 @@ +(letrec (concatN : [Int] -> [Int] -> [Int] l1 : [Int] l2 : [Int]) + (if (isnil l1) + l2 + (let (h) (head l1) + (let (t) (tail l1) + (cons h (concatN t l2))))) +(letrec (concatMapN : (Int -> [Int]) -> [Int] -> [Int] f : (Int -> [Int]) l : [Int]) + (if (isnil l) + (nil : [Int]) + (let (h) (head l) + (let (t) (tail l) + (concatN (f h) (concatMapN f t))))) +(letrec (applyEachN : [Int -> Int] -> Int -> [Int] fs : [Int -> Int] n : Int) + (if (isnil fs) + nil : [Int] + (let (hf) (head fs) + (let (tfs) (tail fs) + (cons (hf n) (applyEachN tfs n))))) +(let (applyEachToEachN fs : [Int -> Int] l : [Int]) + (concatMapN (applyEachN fs) l) +(let (fs) (cons (lambda n : Int (+ n 2)) + (cons (lambda n : Int (* n 2)) nil : [Int -> Int])) +(let (list) (cons 1 (cons 2 (cons 3 nil : [Int]))) +(applyEachToEachN fs list))))))) diff --git a/good/factorial.mim b/good/factorial.mim new file mode 100644 index 0000000..61b813f --- /dev/null +++ b/good/factorial.mim @@ -0,0 +1,5 @@ +(letrec (fact : Int -> Int n : Int) + (if (= n 0) + 1 + (* n (fact (- n 1)))) + (fact 10)) diff --git a/good/fib.mim b/good/fib.mim new file mode 100644 index 0000000..9d2c04f --- /dev/null +++ b/good/fib.mim @@ -0,0 +1,7 @@ +(letrec (fib : Int -> Int n : Int) + (letrec (fibh : (Int -> Int -> Int -> Int) a : Int b : Int k : Int) + (if (= k 0) + a + (fibh b (+ a b) (- k 1))) + (fibh 0 1 n)) + (fib 10)) diff --git a/good/partial.mim b/good/partial.mim new file mode 100644 index 0000000..4e64101 --- /dev/null +++ b/good/partial.mim @@ -0,0 +1,5 @@ +(let (add n : Int m : Int) (+ n m) +(let (inc) (add 1) +(let (double f : (Int -> Int) n : Int) (f (f n)) +(let (add2) (double inc) +(add2 40))))) diff --git a/good/simplify.mim b/good/simplify.mim new file mode 100644 index 0000000..cc5fc1c --- /dev/null +++ b/good/simplify.mim @@ -0,0 +1,23 @@ +(letrec (mapN : (Int -> ) -> [Int] -> [] + f : Int -> l : [Int]) + (if (isnil l) + nil : [] + (let (h) (head l) + (let (t) (tail l) + (cons (f h) (mapN f t))))) +(let (safeDiv n : Int m : Int) + (if (= m 0) + : + : ) +(letrec (simplifyN : [] -> [Int] l : []) + (if (isnil l) + nil : [Int] + (let (h) (head l) + (let (t) (tail l) + (match h + ( (simplifyN t)) + ( (cons n (simplifyN t))))))) +(let (exampleList) + (cons 2 (cons 3 (cons 0 (cons 6 + (cons 7 (cons 0 (cons 1 nil : [Int]))))))) +(simplifyN (mapN (lambda n : Int (safeDiv 6 n)) exampleList)))))) diff --git a/good/tupleAdd.mim b/good/tupleAdd.mim new file mode 100644 index 0000000..807215b --- /dev/null +++ b/good/tupleAdd.mim @@ -0,0 +1,4 @@ +(let (add xy : {Int Int}) + (+ xy.1 xy.2) + (add {1 3})) + -- cgit v1.2.3