Repository navigation
Expand file tree
/
Copy pathmap.sl
More file actions
40 lines (33 loc) · 1.35 KB
/
Copy pathmap.sl
File metadata and controls
40 lines (33 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
; needs: list
; expect: (Cons _ 1 $ Cons _ 2 $ Nil _)
; DESIGN.md section 57: level-polymorphic map via a factory. Needs list.sl first.
(def-lvl F)
(def-fns F $ (many map-factory : (erased (Level) M) ->
(erased (Level) L)
(many (Fn L (erased Type A) (erased Type B)
(many (Fn M (many A x) -> (many B y)) f)
(subterm many (List A) xs) ->
(many (List B) ys))
mapped))
(def-lvl L)
(let ((erased pml)) (prove-predates M L))
(def-fns L $ (many map : (erased Type A) (erased Type B)
(many (Fn M (many A x) -> (many B y)) f)
(subterm many (List A) xs) ->
(many (List B) ys))
(match many xs (((List B) r))
((Nil a) (Nil B))
((Cons a hd tl)
(let ((erased p)) (prove-subterm tl xs))
(Cons B (f (predates pml) hd) $ notail $ map A B f (subterm p) tl))))
(values L map))
(def-lvl I)
(def-fns I $ (many inc : (many (Nat) n) -> (many (Nat) m))
(Succ n))
(let ((erased ML) (many map-nat)) (map-factory I))
(let ((many xs)) (Cons (Nat) (Zero) $ Cons (Nat) (Succ (Zero)) $ Nil (Nat)))
(map-nat (Nat) (Nat) inc xs)
; warns: tests/map.sl:24:20: warning: unnecessary `(predates _)`; drop it
; warns: tests/map.sl:24:60: warning: unnecessary `(subterm _)`; drop it
; warns: tests/map.sl:20:6: warning: lopsided `match`; flatten it with a `let-match` on `Cons`
; warn-unused: no