diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/type/resource.lux | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/stdlib/source/library/lux/type/resource.lux b/stdlib/source/library/lux/type/resource.lux index 8d389b11e..9ecd67608 100644 --- a/stdlib/source/library/lux/type/resource.lux +++ b/stdlib/source/library/lux/type/resource.lux @@ -6,11 +6,11 @@ ["." monad (#+ Monad do) [indexed (#+ IxMonad)]]] [control + ["." maybe] ["." exception (#+ exception:)] ["<>" parser ["<.>" code (#+ Parser)]]] [data - ["." maybe] [text ["%" format (#+ format)]] [collection @@ -26,25 +26,25 @@ abstract]]]) (type: .public (Procedure monad input output value) - {#.doc (doc "A computation that takes a sequence of resource access rights as inputs and yields a different sequence as outputs." - "A procedure yields a result value." - "A procedure can make use of monadic effects.")} + {#.doc (example "A computation that takes a sequence of resource access rights as inputs and yields a different sequence as outputs." + "A procedure yields a result value." + "A procedure can make use of monadic effects.")} (-> input (monad [output value]))) (type: .public (Linear monad value) - {#.doc (doc "A procedure that is constant with regards to resource access rights." - "This means no additional resources will be available after the computation is over." - "This also means no previously available resources will have been consumed.")} + {#.doc (example "A procedure that is constant with regards to resource access rights." + "This means no additional resources will be available after the computation is over." + "This also means no previously available resources will have been consumed.")} (All [keys] (Procedure monad keys keys value))) (type: .public (Affine monad permissions value) - {#.doc (doc "A procedure which expands the number of available resources.")} + {#.doc (example "A procedure which expands the number of available resources.")} (All [keys] (Procedure monad keys [permissions keys] value))) (type: .public (Relevant monad permissions value) - {#.doc (doc "A procedure which reduces the number of available resources.")} + {#.doc (example "A procedure which reduces the number of available resources.")} (All [keys] (Procedure monad [permissions keys] keys value))) @@ -61,7 +61,7 @@ [[keysT value] (input keysI)] ((f value) keysT))))) -(def: .public (run monad procedure) +(def: .public (run! monad procedure) (All [! v] (-> (Monad !) (Linear ! v) (! v))) (do monad [[_ output] (procedure [])] @@ -75,16 +75,16 @@ (in [keys output])))) (abstract: .public Ordered - {#.doc (doc "The mode of keys which CANNOT be swapped, and for whom order of release/consumption matters.")} + {#.doc (example "The mode of keys which CANNOT be swapped, and for whom order of release/consumption matters.")} Any) (abstract: .public Commutative - {#.doc (doc "The mode of keys which CAN be swapped, and for whom order of release/consumption DOES NOT matters.")} + {#.doc (example "The mode of keys which CAN be swapped, and for whom order of release/consumption DOES NOT matters.")} Any) (abstract: .public (Key mode key) - {#.doc (doc "The access right for a resource." - "Without the key for a resource existing somewhere among the available ambient rights, one cannot use a resource.")} + {#.doc (example "The access right for a resource." + "Without the key for a resource existing somewhere among the available ambient rights, one cannot use a resource.")} Any @@ -98,14 +98,14 @@ )) (abstract: .public (Res key value) - {#.doc (doc "A resource locked by a key." - "The 'key' represents the right to access/consume a resource.")} + {#.doc (example "A resource locked by a key." + "The 'key' represents the right to access/consume a resource.")} value (template [<name> <mode> <key>] [(def: .public (<name> monad value) - {#.doc (doc "Makes a value into a resource and adds the key/access-right to it to the ambient keyring for future use.")} + {#.doc (example "Makes a value into a resource and adds the key/access-right to it to the ambient keyring for future use.")} (All [! v] (Ex [k] (-> (Monad !) v (Affine ! (Key <mode> k) (Res k v))))) (function (_ keys) (\ monad in [[(<key> []) keys] (:abstraction value)])))] @@ -115,7 +115,7 @@ ) (def: .public (read monad resource) - {#.doc (doc "Access the value of a resource, so long as its key is available.")} + {#.doc (example "Access the value of a resource, so long as its key is available.")} (All [! v k m] (-> (Monad !) (Res k v) (Relevant ! (Key m k) v))) (function (_ [key keys]) @@ -148,17 +148,17 @@ (\ monad in [context []]))) (syntax: .public (exchange {swaps ..indices}) - {#.doc (doc "A function that can exchange the keys for resource, so long as they are commutative." - "This keys will be placed at the front of the keyring in the order they are specified." - "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))))} - (macro.with_gensyms [g!_ g!context g!!] + {#.doc (example "A function that can exchange the keys for resource, so long as they are commutative." + "This keys will be placed at the front of the keyring in the order they are specified." + "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))))} + (macro.with_identifiers [g!_ g!context g!!] (case swaps #.End (in (list (` (~! no_op)))) @@ -166,7 +166,7 @@ (#.Item head tail) (do {! meta.monad} [.let [max_idx (list\fold n.max head tail)] - g!inputs (<| (monad.seq !) (list.repeated (inc max_idx)) (macro.gensym "input")) + g!inputs (<| (monad.seq !) (list.repeated (inc max_idx)) (macro.identifier "input")) .let [g!outputs (|> (monad.fold maybe.monad (function (_ from to) (do maybe.monad @@ -197,18 +197,18 @@ (template [<name> <from> <to>] [(syntax: .public (<name> {amount ..amount}) - {#.doc (doc "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))))} - (macro.with_gensyms [g!_ g!context g!!] + {#.doc (example "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))))} + (macro.with_identifiers [g!_ g!context g!!] (do {! meta.monad} - [g!keys (|> (macro.gensym "keys") + [g!keys (|> (macro.identifier "keys") (list.repeated amount) (monad.seq !))] (in (list (` (: (All [(~ g!!) (~+ g!keys) (~ g!context)] |