m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2018-05-13 21:12:57 +0200
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2018-05-13 21:17:15 +0200
commit76478dd79705313860c00008cee75c48db814ecc (patch)
tree2d08f2577674e9c96c96fe1653073732f5616fdc
parent3939b1fa57007fabb350dc91eb13b66f9480c244 (diff)
Add examples
-rw-r--r--bad/appType.mim1
-rw-r--r--bad/divideBy0.mim2
-rw-r--r--bad/headOfNil.mim1
-rw-r--r--bad/ifType.mim3
-rw-r--r--bad/outOfTupleBounds.mim4
-rw-r--r--bad/tailOfNil.mim1
-rw-r--r--good/concat.mim7
-rw-r--r--good/curry.mim8
-rw-r--r--good/eachToEach.mim24
-rw-r--r--good/factorial.mim5
-rw-r--r--good/fib.mim7
-rw-r--r--good/partial.mim5
-rw-r--r--good/simplify.mim23
-rw-r--r--good/tupleAdd.mim4
14 files changed, 95 insertions, 0 deletions
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 -> <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}))
+