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/eachToEach.mim | |
parent | 3939b1fa57007fabb350dc91eb13b66f9480c244 (diff) |
Add examples
Diffstat (limited to 'good/eachToEach.mim')
-rw-r--r-- | good/eachToEach.mim | 24 |
1 files changed, 24 insertions, 0 deletions
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))))))) |