blob: 24f7005fde605a32a0a5e8bb83b0f4429ead4e90 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
(.module:
[library
[lux #*
[abstract
[functor (#+ Functor)]
comonad]
[type
implicit]]])
(type: .public (Store s a)
(Record
{#cursor s
#peek (-> s a)}))
(def: (extend f wa)
(All (_ s a b) (-> (-> (Store s a) b) (Store s a) (Store s b)))
{#cursor (value@ #cursor wa)
#peek (function (_ s) (f (with@ #cursor s wa)))})
(implementation: .public functor
(All (_ s) (Functor (Store s)))
(def: (each f fa)
(extend (function (_ store)
(f (\ store peek (\ store cursor))))
fa)))
(implementation: .public comonad
(All (_ s) (CoMonad (Store s)))
(def: &functor
..functor)
(def: (out wa)
(\\ peek (\\ cursor)))
(def: disjoint
(extend id)))
(def: .public (peeks trans store)
(All (_ s a) (-> (-> s s) (Store s a) a))
(|> (\\ cursor) trans (\\ peek)))
(def: .public (seek cursor store)
(All (_ s a) (-> s (Store s a) (Store s a)))
(\ (\\ disjoint store) peek cursor))
(def: .public (seeks change store)
(All (_ s a) (-> (-> s s) (Store s a) (Store s a)))
(|> store (\\ disjoint) (peeks change)))
(def: .public (experiment Functor<f> change store)
(All (_ f s a) (-> (Functor f) (-> s (f s)) (Store s a) (f a)))
(\ Functor<f> each (\\ peek) (change (\\ cursor))))
|