blob: 414a74ddd24a98ff0693fb594f69aa96263cecae (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
(.using
[library
[lux "*"
[abstract
["[0]" equivalence {"+" Equivalence}]]
[control
["[0]" maybe]
["[0]" try {"+" Try}]]
[data
[text
["%" format {"+" Format}]]
[format
[binary {"+" Writer}]]]
[type
[primitive "*"]]]]
["[0]" ///// "_"
[encoding
["[1][0]" unsigned {"+" U2}]]])
(primitive: .public Stack
U2
(template [<frames> <name>]
[(def: .public <name>
Stack
(|> <frames> /////unsigned.u2 maybe.trusted abstraction))]
[0 empty]
[1 catch]
)
(def: .public equivalence
(Equivalence Stack)
(# equivalence.functor each
(|>> representation)
/////unsigned.equivalence))
(def: .public writer
(Writer Stack)
(|>> representation /////unsigned.writer/2))
(def: stack
(-> U2 Stack)
(|>> abstraction))
(template [<op> <name>]
[(def: .public (<name> amount)
(-> U2 (-> Stack (Try Stack)))
(|>> representation
(<op> amount)
(# try.functor each ..stack)))]
[/////unsigned.+/2 push]
[/////unsigned.-/2 pop]
)
(def: .public (max left right)
(-> Stack Stack Stack)
(abstraction
(/////unsigned.max/2 (representation left)
(representation right))))
(def: .public format
(Format Stack)
(|>> representation /////unsigned.value %.nat))
)
(def: .public length
/////unsigned.bytes/2)
|