aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2018-04-05 08:05:04 -0400
committerEduardo Julian2018-04-05 08:05:04 -0400
commit84d7e87817cd2c074653b34d028c8fa807febc7f (patch)
tree1e6ba39b5a33a0116e176cebe90f16681a4c469b /stdlib
parent435771d3c4d4ffa791805e7006ee3bde488a4090 (diff)
- Can now use resource/substructural types in pure computations.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/type/resource.lux38
-rw-r--r--stdlib/test/test/lux/type/resource.lux36
2 files changed, 41 insertions, 33 deletions
diff --git a/stdlib/source/lux/type/resource.lux b/stdlib/source/lux/type/resource.lux
index 7de8fddf5..526dbecc9 100644
--- a/stdlib/source/lux/type/resource.lux
+++ b/stdlib/source/lux/type/resource.lux
@@ -4,7 +4,8 @@
["ex" exception #+ exception:]
[monad #+ Monad do]
(monad [indexed #+ IxMonad]))
- (data [maybe]
+ (data [identity #+ Identity]
+ [maybe]
[product]
[number]
text/format
@@ -64,8 +65,9 @@
[output procedure]
(wrap [keys output]))))]
- [IxMonad<Sync> IO io.Monad<IO> run lift]
- [IxMonad<Async> Promise promise.Monad<Promise> run! lift!]
+ [IxMonad<Pure> Identity identity.Monad<Identity> run-pure lift-pure]
+ [IxMonad<Sync> IO io.Monad<IO> run-sync lift-sync]
+ [IxMonad<Async> Promise promise.Monad<Promise> run-async lift-async]
)
(abstract: #export Ordered {} [])
@@ -97,10 +99,12 @@
(function (_ keys)
(:: <monad> wrap [[(<key> []) keys] (@abstraction value)])))]
- [ordered IO io.Monad<IO> Ordered ordered-key]
- [ordered! Promise promise.Monad<Promise> Ordered ordered-key]
- [commutative IO io.Monad<IO> Commutative commutative-key]
- [commutative! Promise promise.Monad<Promise> Commutative commutative-key])
+ [ordered-pure Identity identity.Monad<Identity> Ordered ordered-key]
+ [ordered-sync IO io.Monad<IO> Ordered ordered-key]
+ [ordered-async Promise promise.Monad<Promise> Ordered ordered-key]
+ [commutative-sync IO io.Monad<IO> Commutative commutative-key]
+ [commutative-pure Identity identity.Monad<Identity> Commutative commutative-key]
+ [commutative-async Promise promise.Monad<Promise> Commutative commutative-key])
(do-template [<name> <m> <monad>]
[(def: #export (<name> resource)
@@ -109,8 +113,9 @@
(function (_ [key keys])
(:: <monad> wrap [keys (@representation resource)])))]
- [read IO io.Monad<IO>]
- [read! Promise promise.Monad<Promise>]))
+ [read-pure Identity identity.Monad<Identity>]
+ [read-sync IO io.Monad<IO>]
+ [read-async Promise promise.Monad<Promise>]))
(exception: #export (Index-Cannot-Be-Repeated {index Nat})
(%n index))
@@ -165,8 +170,9 @@
(function ((~ g!_) [(~+ g!inputs) (~ g!context)])
(:: (~! <monad>) (~' wrap) [[(~+ g!outputs) (~ g!context)] []]))))))))))]
- [exchange IO io.Monad<IO>]
- [exchange! Promise promise.Monad<Promise>])
+ [exchange-pure Identity identity.Monad<Identity>]
+ [exchange-sync IO io.Monad<IO>]
+ [exchange-async Promise promise.Monad<Promise>])
(def: amount
(Syntax Nat)
@@ -189,8 +195,10 @@
(function ((~ g!_) [<from> (~ g!context)])
(:: (~! <monad>) (~' wrap) [[<to> (~ g!context)] []])))))))))]
- [group IO io.Monad<IO> (~+ g!keys) [(~+ g!keys)]]
- [group! Promise promise.Monad<Promise> (~+ g!keys) [(~+ g!keys)]]
- [un-group IO io.Monad<IO> [(~+ g!keys)] (~+ g!keys)]
- [un-group! Promise promise.Monad<Promise> [(~+ g!keys)] (~+ g!keys)]
+ [group-pure Identity identity.Monad<Identity> (~+ g!keys) [(~+ g!keys)]]
+ [group-sync IO io.Monad<IO> (~+ g!keys) [(~+ g!keys)]]
+ [group-async Promise promise.Monad<Promise> (~+ g!keys) [(~+ g!keys)]]
+ [un-group-pure Identity identity.Monad<Identity> [(~+ g!keys)] (~+ g!keys)]
+ [un-group-sync IO io.Monad<IO> [(~+ g!keys)] (~+ g!keys)]
+ [un-group-async Promise promise.Monad<Promise> [(~+ g!keys)] (~+ g!keys)]
)
diff --git a/stdlib/test/test/lux/type/resource.lux b/stdlib/test/test/lux/type/resource.lux
index b02a8d583..c92af92e8 100644
--- a/stdlib/test/test/lux/type/resource.lux
+++ b/stdlib/test/test/lux/type/resource.lux
@@ -11,36 +11,36 @@
(test "Can produce and consume keys in an ordered manner."
(<| (n/= (n/+ +123 +456))
io.run
- resource.run
+ resource.run-sync
(do resource.IxMonad<Sync>
- [res|left (resource.ordered +123)
- res|right (resource.ordered +456)
- right (resource.read res|right)
- left (resource.read res|left)]
+ [res|left (resource.ordered-sync +123)
+ res|right (resource.ordered-sync +456)
+ right (resource.read-sync res|right)
+ left (resource.read-sync res|left)]
(wrap (n/+ left right)))))
(test "Can exchange commutative keys."
(<| (n/= (n/+ +123 +456))
io.run
- resource.run
+ resource.run-sync
(do resource.IxMonad<Sync>
- [res|left (resource.commutative +123)
- res|right (resource.commutative +456)
- _ (resource.exchange [+1 +0])
- left (resource.read res|left)
- right (resource.read res|right)]
+ [res|left (resource.commutative-sync +123)
+ res|right (resource.commutative-sync +456)
+ _ (resource.exchange-sync [+1 +0])
+ left (resource.read-sync res|left)
+ right (resource.read-sync res|right)]
(wrap (n/+ left right)))))
(test "Can group and un-group keys."
(<| (n/= (n/+ +123 +456))
io.run
- resource.run
+ resource.run-sync
(do resource.IxMonad<Sync>
- [res|left (resource.commutative +123)
- res|right (resource.commutative +456)
- _ (resource.group +2)
- _ (resource.un-group +2)
- right (resource.read res|right)
- left (resource.read res|left)]
+ [res|left (resource.commutative-sync +123)
+ res|right (resource.commutative-sync +456)
+ _ (resource.group-sync +2)
+ _ (resource.un-group-sync +2)
+ right (resource.read-sync res|right)
+ left (resource.read-sync res|left)]
(wrap (n/+ left right)))))
))