diff options
-rw-r--r-- | stdlib/source/lux/concurrency/actor.lux | 6 | ||||
-rw-r--r-- | stdlib/source/lux/concurrency/frp.lux | 84 | ||||
-rw-r--r-- | stdlib/source/lux/concurrency/stm.lux | 16 | ||||
-rw-r--r-- | stdlib/test/test/lux/concurrency/frp.lux | 20 |
4 files changed, 63 insertions, 63 deletions
diff --git a/stdlib/source/lux/concurrency/actor.lux b/stdlib/source/lux/concurrency/actor.lux index 93f1ed6d8..dd34a7ae8 100644 --- a/stdlib/source/lux/concurrency/actor.lux +++ b/stdlib/source/lux/concurrency/actor.lux @@ -61,15 +61,15 @@ {#mailbox (stm;var (:! (Message ($ +0)) [])) #kill-switch (P;promise Unit) #obituary (P;promise (Obituary ($ +0)))}) - mailbox-chan (io;run (stm;follow (get@ #mailbox self))) - |mailbox| (stm;var mailbox-chan) + mailbox-channel (io;run (stm;follow (get@ #mailbox self))) + |mailbox| (stm;var mailbox-channel) _ (P/map (function [_] (io;run (do Monad<IO> [mb (stm;read! |mailbox|)] (frp;close mb)))) (get@ #kill-switch self)) process (loop [state init - messages mailbox-chan] + messages mailbox-channel] (do P;Monad<Promise> [?messages+ messages] (case ?messages+ diff --git a/stdlib/source/lux/concurrency/frp.lux b/stdlib/source/lux/concurrency/frp.lux index 538bbdcbd..a1839850d 100644 --- a/stdlib/source/lux/concurrency/frp.lux +++ b/stdlib/source/lux/concurrency/frp.lux @@ -13,22 +13,22 @@ (.. ["&" promise])) ## [Types] -(type: #export (Chan a) +(type: #export (Channel a) {#;doc "An asynchronous channel of values which may be closed. Reading from a channel does not remove the read piece of data, as it can still be accessed if you have an earlier node of the channel."} - (&;Promise (Maybe [a (Chan a)]))) + (&;Promise (Maybe [a (Channel a)]))) ## [Syntax] -(syntax: #export (chan [type s;any]) - {#;doc (doc "Makes an uninitialized Chan (in this case, of Unit)." - (chan Unit))} - (wrap (list (` (: (Chan (~ type)) +(syntax: #export (channel [type s;any]) + {#;doc (doc "Makes an uninitialized Channel (in this case, of Nat)." + (channel Nat))} + (wrap (list (` (: (Channel (~ type)) (&;promise' #;None)))))) ## [Values] (def: #export (filter p xs) - (All [a] (-> (-> a Bool) (Chan a) (Chan a))) + (All [a] (-> (-> a Bool) (Channel a) (Channel a))) (do &;Monad<Promise> [?x+xs xs] (case ?x+xs @@ -39,16 +39,16 @@ (def: #export (write value target) {#;doc "Write to a channel, so long as it's still open."} - (All [a] (-> a (Chan a) (IO (Maybe (Chan a))))) + (All [a] (-> a (Channel a) (IO (Maybe (Channel a))))) (case (&;poll target) - (^template [<case> <chan-to-write>] + (^template [<case> <channel-to-write>] <case> (do Monad<IO> - [#let [new-tail (chan ($ +0))] - done? (&;resolve (#;Some [value new-tail]) <chan-to-write>)] + [#let [new-tail (channel ($ +0))] + done? (&;resolve (#;Some [value new-tail]) <channel-to-write>)] (if done? (wrap (#;Some new-tail)) - (write value <chan-to-write>)))) + (write value <channel-to-write>)))) ([#;None target] [(#;Some (#;Some [_ target'])) target']) @@ -57,15 +57,15 @@ )) (def: #export (close target) - (All [a] (-> (Chan a) (IO Bool))) + (All [a] (-> (Channel a) (IO Bool))) (case (&;poll target) - (^template [<case> <chan-to-write>] + (^template [<case> <channel-to-write>] <case> (do Monad<IO> - [done? (&;resolve #;None <chan-to-write>)] + [done? (&;resolve #;None <channel-to-write>)] (if done? (wrap true) - (close <chan-to-write>)))) + (close <channel-to-write>)))) ([#;None target] [(#;Some (#;Some [_ target'])) target']) @@ -74,7 +74,7 @@ )) (def: (pipe' input output) - (All [a] (-> (Chan a) (Chan a) (&;Promise Unit))) + (All [a] (-> (Channel a) (Channel a) (&;Promise Unit))) (do &;Monad<Promise> [?x+xs input] (case ?x+xs @@ -88,7 +88,7 @@ (def: #export (pipe input output) {#;doc "Copy/pipe the contents of a channel on to another."} - (All [a] (-> (Chan a) (Chan a) (&;Promise Unit))) + (All [a] (-> (Channel a) (Channel a) (&;Promise Unit))) (do &;Monad<Promise> [_ (pipe' input output)] (exec (io;run (close output)) @@ -96,8 +96,8 @@ (def: #export (merge xss) {#;doc "Fuse all the elements in a list of channels by piping them onto a new output channel."} - (All [a] (-> (List (Chan a)) (Chan a))) - (let [output (chan ($ +0))] + (All [a] (-> (List (Channel a)) (Channel a))) + (let [output (channel ($ +0))] (exec (do &;Monad<Promise> [_ (mapM @ (function [input] (pipe' input output)) xss)] (exec (io;run (close output)) @@ -106,7 +106,7 @@ (def: #export (fold f init xs) {#;doc "Asynchronous fold over channels."} - (All [a b] (-> (-> b a (&;Promise a)) a (Chan b) (&;Promise a))) + (All [a b] (-> (-> b a (&;Promise a)) a (Channel b) (&;Promise a))) (do &;Monad<Promise> [?x+xs xs] (case ?x+xs @@ -117,7 +117,7 @@ (def: #export (folds f init xs) {#;doc "A channel of folds."} - (All [a b] (-> (-> b a (&;Promise a)) a (Chan b) (Chan a))) + (All [a b] (-> (-> b a (&;Promise a)) a (Channel b) (Channel a))) (do &;Monad<Promise> [?x+xs xs] (case ?x+xs @@ -127,7 +127,7 @@ (folds f init' xs'))))) (def: (distinct' eq last-one xs) - (All [a] (-> (Eq a) a (Chan a) (Chan a))) + (All [a] (-> (Eq a) a (Channel a) (Channel a))) (let [(^open) eq] (do &;Monad<Promise> [?x+xs xs] @@ -139,7 +139,7 @@ (def: #export (distinct eq xs) {#;doc "Multiple consecutive equal values in the input channel will just be single value in the output channel."} - (All [a] (-> (Eq a) (Chan a) (Chan a))) + (All [a] (-> (Eq a) (Channel a) (Channel a))) (let [(^open) eq] (do &;Monad<Promise> [?x+xs xs] @@ -149,7 +149,7 @@ (def: #export (consume xs) {#;doc "Reads the entirety of a channel's contents and returns them as a list."} - (All [a] (-> (Chan a) (&;Promise (List a)))) + (All [a] (-> (Channel a) (&;Promise (List a)))) (do &;Monad<Promise> [?x+xs' xs] (case ?x+xs' @@ -162,13 +162,13 @@ (wrap (#;Cons x =xs)))))) (def: #export (once p) - (All [a] (-> (&;Promise a) (Chan a))) + (All [a] (-> (&;Promise a) (Channel a))) (do &;Monad<Promise> [x p] (wrap (#;Some [x (wrap #;None)])))) (def: #export (poll time action) - (All [a] (-> Nat (IO (Maybe a)) (Chan a))) + (All [a] (-> Nat (IO (Maybe a)) (Channel a))) (do &;Monad<Promise> [?output (&;future action)] (case ?output @@ -181,7 +181,7 @@ (wrap (#;Some [head (poll time action)])))))) (def: #export (periodic time value) - (All [a] (-> Nat a (Chan a))) + (All [a] (-> Nat a (Channel a))) (do &;Monad<Promise> [] (wrap (#;Some [value (do @ @@ -189,7 +189,7 @@ (periodic time value))])))) (def: #export (sequential time xs) - (All [a] (-> Nat (List a) (Chan a))) + (All [a] (-> Nat (List a) (Channel a))) (do &;Monad<Promise> [] (case xs @@ -202,7 +202,7 @@ (sequential time xs'))]))))) (def: #export (cycle time values) - (All [a] (-> Nat (List a) (Chan a))) + (All [a] (-> Nat (List a) (Channel a))) (do &;Monad<Promise> [] (case values @@ -231,7 +231,7 @@ xs')) (def: #export (sliding-window max inputs) - (All [a] (-> Nat (Chan a) (Chan (List a)))) + (All [a] (-> Nat (Channel a) (Channel (List a)))) (let [(^open) &;Monad<Promise>] (folds (function [input window] (let [window' (L/append window (list input))] @@ -242,7 +242,7 @@ inputs))) (def: #export (iterate f init) - (All [a] (-> (-> a (&;Promise (Maybe a))) a (Chan a))) + (All [a] (-> (-> a (&;Promise (Maybe a))) a (Channel a))) (do &;Monad<Promise> [] (wrap (#;Some [init (do @ @@ -255,7 +255,7 @@ (iterate f init')))])))) (def: #export (sample time inputs) - (All [a] (-> Nat (Chan a) (Chan a))) + (All [a] (-> Nat (Channel a) (Channel a))) (do &;Monad<Promise> [?h+t inputs] (case ?h+t @@ -276,7 +276,7 @@ (wrap (#;Some [value (sample time next-inputs)])))))) ## [Structures] -(struct: #export _ (Functor Chan) +(struct: #export _ (Functor Channel) (def: (map f xs) (:: &;Functor<Promise> map (function [?x+xs] @@ -285,26 +285,26 @@ (#;Some [x xs']) (#;Some [(f x) (map f xs')]))) xs))) -(struct: #export _ (Applicative Chan) - (def: functor Functor<Chan>) +(struct: #export _ (Applicative Channel) + (def: functor Functor<Channel>) (def: (wrap a) (let [(^open) &;Monad<Promise>] (wrap (#;Some [a (wrap #;None)])))) (def: (apply ff fa) - (let [fb (chan ($ +1))] - (exec (let [(^open) Functor<Chan>] + (let [fb (channel ($ +1))] + (exec (let [(^open) Functor<Channel>] (map (function [f] (pipe (map f fa) fb)) ff)) fb)))) -(struct: #export _ (Monad Chan) - (def: applicative Applicative<Chan>) +(struct: #export _ (Monad Channel) + (def: applicative Applicative<Channel>) (def: (join mma) - (let [output (chan ($ +0))] - (exec (let [(^open) Functor<Chan>] + (let [output (channel ($ +0))] + (exec (let [(^open) Functor<Channel>] (map (function [ma] (pipe ma output)) mma)) diff --git a/stdlib/source/lux/concurrency/stm.lux b/stdlib/source/lux/concurrency/stm.lux index ed9f28038..946f9bac4 100644 --- a/stdlib/source/lux/concurrency/stm.lux +++ b/stdlib/source/lux/concurrency/stm.lux @@ -127,20 +127,20 @@ (def: #export (follow target) {#;doc "Creates a channel that will receive all changes to the value of the given var."} - (All [a] (-> (Var a) (IO (frp;Chan a)))) - (let [head (frp;chan ($ +0)) - chan-var (var head) + (All [a] (-> (Var a) (IO (frp;Channel a)))) + (let [head (frp;channel ($ +0)) + channel-var (var head) observer (function [label value] - (case (io;run (|> chan-var raw-read (frp;write value))) + (case (io;run (|> channel-var raw-read (frp;write value))) #;None - ## By closing the output Chan, the + ## By closing the output Channel, the ## observer becomes obsolete. (atom;update (function [[value observers]] [value (dict;remove label observers)]) target) (#;Some tail') - (write! tail' chan-var)))] + (write! tail' channel-var)))] (do Monad<IO> [_ (atom;update (function [[value observers]] (let [label (Nat/encode (L/fold (function [key base] @@ -226,7 +226,7 @@ (atom false)) (def: (process-commit commits) - (-> (frp;Chan [(STM Unit) (P;Promise Unit)]) + (-> (frp;Channel [(STM Unit) (P;Promise Unit)]) (P;Promise Unit)) (do P;Monad<Promise> [?head+tail commits] @@ -257,7 +257,7 @@ (if was-first? (do Monad<IO> [inputs (follow pending-commits)] - (exec (process-commit (:! (frp;Chan [(STM Unit) (P;Promise Unit)]) + (exec (process-commit (:! (frp;Channel [(STM Unit) (P;Promise Unit)]) inputs)) (wrap []))) (wrap []))) diff --git a/stdlib/test/test/lux/concurrency/frp.lux b/stdlib/test/test/lux/concurrency/frp.lux index 3447a55b2..302a59d06 100644 --- a/stdlib/test/test/lux/concurrency/frp.lux +++ b/stdlib/test/test/lux/concurrency/frp.lux @@ -9,19 +9,19 @@ lux/test) (def: (to-channel values) - (-> (List Int) (&;Chan Int)) - (let [_chan (&;chan Int)] + (-> (List Int) (&;Channel Int)) + (let [_channel (&;channel Int)] (io;run (do Monad<IO> - [_ (mapM @ (function [value] (&;write value _chan)) + [_ (mapM @ (function [value] (&;write value _channel)) values) - _ (&;close _chan)] - (wrap _chan))))) + _ (&;close _channel)] + (wrap _channel))))) (context: "FRP" ($_ seq (do P;Monad<Promise> [elems (&;consume (to-channel (list 0 1 2 3 4 5)))] - (test "Can consume a chan into a list." + (test "Can consume a channel into a list." (case elems (^ (list 0 1 2 3 4 5)) true @@ -31,7 +31,7 @@ (do P;Monad<Promise> [elems (&;consume (let [input (to-channel (list 0 1 2 3 4 5)) - output (&;chan Int)] + output (&;channel Int)] (exec (&;pipe input output) output)))] (test "Can pipe one channel into another." @@ -89,7 +89,7 @@ false))) (do P;Monad<Promise> - [elems (&;consume (:: &;Functor<Chan> map i.inc (to-channel (list 0 1 2 3 4 5))))] + [elems (&;consume (:: &;Functor<Channel> map i.inc (to-channel (list 0 1 2 3 4 5))))] (test "Functor goes over every element in a channel." (case elems (^ (list 1 2 3 4 5 6)) @@ -99,7 +99,7 @@ false))) (do P;Monad<Promise> - [elems (&;consume (let [(^open) &;Applicative<Chan>] + [elems (&;consume (let [(^open) &;Applicative<Channel>] (apply (wrap i.inc) (wrap 12345))))] (test "Applicative works over all channel values." (case elems @@ -110,7 +110,7 @@ false))) (do P;Monad<Promise> - [elems (&;consume (do &;Monad<Chan> + [elems (&;consume (do &;Monad<Channel> [f (wrap i.inc) a (wrap 12345)] (wrap (f a))))] |