aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/type/resource.lux
blob: 1fbd8997e99fec9f4ae564d191a72b479d7020aa (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
(.using
 [library
  [lux (.except and)
   ["$" documentation (.only documentation:)]
   [control
    ["<>" parser
     ["<[0]>" code]]]
   [data
    ["[0]" text (.only \n)
     ["%" \\format (.only format)]]]
   [macro
    ["[0]" template]]]]
 [\\library
  ["[0]" /]])

(documentation: (/.Procedure monad input output value)
  (format "A computation that takes a sequence of resource access rights as inputs and yields a different sequence as outputs."
          \n "A procedure yields a result value."
          \n "A procedure can make use of monadic effects."))

(documentation: (/.Linear monad value)
  (format "A procedure that is constant with regards to resource access rights."
          \n "This means no additional resources will be available after the computation is over."
          \n "This also means no previously available resources will have been consumed."))

(documentation: (/.Affine monad permissions value)
  "A procedure which expands the number of available resources.")

(documentation: (/.Relevant monad permissions value)
  "A procedure which reduces the number of available resources.")

(documentation: /.run!
  ""
  [(run! monad procedure)])

(documentation: /.lifted
  ""
  [(lifted monad procedure)])

(documentation: /.Ordered
  "The mode of keys which CANNOT be swapped, and for whom order of release/consumption matters.")

(documentation: /.Commutative
  "The mode of keys which CAN be swapped, and for whom order of release/consumption DOES NOT matters.")

(documentation: (/.Key mode key)
  (format "The access right for a resource."
          \n "Without the key for a resource existing somewhere among the available ambient rights, one cannot use a resource."))

(documentation: (/.Res key value)
  (format "A resource locked by a key."
          \n "The 'key' represents the right to access/consume a resource."))

(with_template [<name>]
  [(documentation: <name>
     "Makes a value into a resource and adds the key/access-right to it to the ambient keyring for future use.")]

  [/.ordered]
  [/.commutative]
  )

(documentation: /.read
  "Access the value of a resource, so long as its key is available."
  [(read monad resource)])

(documentation: /.exchange
  (format "A function that can exchange the keys for resource, so long as they are commutative."
          \n "This keys will be placed at the front of the keyring in the order they are specified."
          \n "The specific keys must be specified based of their index into the current keyring.")
  [(do (monad !)
     [res|left (commutative ! pre)
      res|right (commutative ! post)
      _ ((exchange [1 0]) !)
      left (read ! res|left)
      right (read ! res|right)]
     (in (format left right)))])

(with_template [<name>]
  [(documentation: <name>
     "Group/un-group keys in the keyring into/out-of tuples."
     [(do (monad !)
        [res|left (commutative ! pre)
         res|right (commutative ! post)
         _ ((group 2) !)
         _ ((un_group 2) !)
         right (read ! res|right)
         left (read ! res|left)]
        (in (format left right)))])]

  [/.group]
  [/.un_group]
  )

(.def .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..Procedure
             ..Linear
             ..Affine
             ..Relevant
             ..run!
             ..lifted
             ..Ordered
             ..Commutative
             ..Key
             ..Res
             ..ordered
             ..commutative
             ..read
             ..exchange
             ..group
             ..un_group
             ($.default /.monad)
             ($.default /.index_cannot_be_repeated)
             ($.default /.amount_cannot_be_zero)]
            []))