m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/good/simplify.mim
blob: cc5fc1c9f708f6c28a837a1dc7f373130d7d410a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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))))))