diff options
Diffstat (limited to 'good')
-rw-r--r-- | good/concat.mim | 7 | ||||
-rw-r--r-- | good/curry.mim | 8 | ||||
-rw-r--r-- | good/eachToEach.mim | 24 | ||||
-rw-r--r-- | good/factorial.mim | 5 | ||||
-rw-r--r-- | good/fib.mim | 7 | ||||
-rw-r--r-- | good/partial.mim | 5 | ||||
-rw-r--r-- | good/simplify.mim | 23 | ||||
-rw-r--r-- | good/tupleAdd.mim | 4 |
8 files changed, 83 insertions, 0 deletions
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 -> <nothing : {} just : Int>) -> [Int] -> [<nothing : {} just : Int>] + f : Int -> <nothing : {} just : Int> l : [Int]) + (if (isnil l) + nil : [<nothing : {} just : Int>] + (let (h) (head l) + (let (t) (tail l) + (cons (f h) (mapN f t))))) +(let (safeDiv n : Int m : Int) + (if (= m 0) + <nothing {}> : <nothing : {} just : Int> + <just (/ n m)> : <nothing : {} just : Int>) +(letrec (simplifyN : [<nothing : {} just : Int>] -> [Int] l : [<nothing : {} just : Int>]) + (if (isnil l) + nil : [Int] + (let (h) (head l) + (let (t) (tail l) + (match h + (<nothing x> (simplifyN t)) + (<just n> (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})) + |