m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/good/simplify.mim
diff options
context:
space:
mode:
Diffstat (limited to 'good/simplify.mim')
-rw-r--r--good/simplify.mim23
1 files changed, 23 insertions, 0 deletions
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))))))