diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2018-05-13 21:12:57 +0200 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2018-05-13 21:17:15 +0200 |
commit | 76478dd79705313860c00008cee75c48db814ecc (patch) | |
tree | 2d08f2577674e9c96c96fe1653073732f5616fdc /good/simplify.mim | |
parent | 3939b1fa57007fabb350dc91eb13b66f9480c244 (diff) |
Add examples
Diffstat (limited to 'good/simplify.mim')
-rw-r--r-- | good/simplify.mim | 23 |
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)))))) |