diff options
Diffstat (limited to 'stdlib/source/library/lux/control')
37 files changed, 525 insertions, 525 deletions
diff --git a/stdlib/source/library/lux/control/concatenative.lux b/stdlib/source/library/lux/control/concatenative.lux index 4661a546e..2fe9f788f 100644 --- a/stdlib/source/library/lux/control/concatenative.lux +++ b/stdlib/source/library/lux/control/concatenative.lux @@ -32,29 +32,29 @@ [#bottom (Maybe Code) #top (List Code)])) -(def: top +(def top (Parser (List Code)) (<code>.tuple (<>.some <code>.any))) -(def: bottom +(def bottom (Parser Code) (<code>.not ..top)) -(def: stack +(def stack (Parser Stack) (<>.either (<>.and (<>.maybe bottom) ..top) (<>.and (<>#each (|>> {.#Some}) bottom) (<>#in (list))))) -(def: (stack_type tops bottom) +(def (stack_type tops bottom) (-> (List Code) Code Code) (list#mix (function (_ top bottom) (` [(~ bottom) (~ top)])) bottom tops)) -(def: .public => +(def .public => (syntax (_ [inputs stack outputs stack]) (with_symbols [g!_ common_bottom] @@ -70,14 +70,14 @@ (` (-> (~ input_stack) (~ output_stack)))))))))) -(def: .public (value it) +(def .public (value it) (All (_ ,,, a) (-> (=> [] ,,, [a]) a)) (|> [] it product.right)) -(def: .public apply +(def .public apply (syntax (_ [arity (<>.only (n.> 0) <code>.nat)]) (with_symbols [g!_ g!func g!stack g!output] (monad.do [! meta.monad] @@ -90,65 +90,65 @@ [(~ g!stack) ((~ g!func) (~+ g!inputs))])))))))))) (with_template [<arity>] - [(`` (def: .public (~~ (template.symbol ["apply_" <arity>])) + [(`` (def .public (~~ (template.symbol ["apply_" <arity>])) (..apply <arity>)))] [1] [2] [3] [4] [5] [6] [7] [8] ) -(def: .public (push x) +(def .public (push x) (All (_ a) (-> a (=> [] [a]))) (function (_ stack) [stack x])) -(def: .public drop +(def .public drop (All (_ t) (=> [t] [])) (function (_ [stack top]) stack)) -(def: .public nip +(def .public nip (All (_ _ a) (=> [_ a] [a])) (function (_ [[stack _] top]) [stack top])) -(def: .public dup +(def .public dup (All (_ a) (=> [a] [a a])) (function (_ [stack top]) [[stack top] top])) -(def: .public swap +(def .public swap (All (_ a b) (=> [a b] [b a])) (function (_ [[stack l] r]) [[stack r] l])) -(def: .public left_rotation +(def .public left_rotation (All (_ a b c) (=> [a b c] [b c a])) (function (_ [[[stack a] b] c]) [[[stack b] c] a])) -(def: .public right_rotation +(def .public right_rotation (All (_ a b c) (=> [a b c] [c a b])) (function (_ [[[stack a] b] c]) [[[stack c] a] b])) -(def: .public && +(def .public && (All (_ a b) (=> [a b] [(Tuple a b)])) (function (_ [[stack l] r]) [stack [l r]])) -(def: .public left +(def .public left (All (_ a b) (=> [a] [(Or a b)])) (function (_ [stack l]) [stack {0 #0 l}])) -(def: .public right +(def .public right (All (_ a b) (=> [b] [(Or a b)])) (function (_ [stack r]) [stack {0 #1 r}])) (with_template [<input> <output> <word> <func>] - [(`` (def: .public <word> + [(`` (def .public <word> (=> [<input> <input>] [<output>]) (function (_ [[stack subject] param]) [stack (<func> param subject)])))] @@ -198,7 +198,7 @@ [Frac Bit f/>= f.>=] ) -(def: .public if +(def .public if (All (_ ,,,0 ,,,1) (type.let [then (=> ,,,0 ,,,1) else (=> ,,,0 ,,,1)] @@ -209,7 +209,7 @@ (then stack) (else stack)))) -(def: .public call +(def .public call (All (_ ,,,0 ,,,1) (type.let [quote (=> ,,,0 ,,,1)] (=> ,,,0 [quote] @@ -217,7 +217,7 @@ (function (_ [stack quote]) (quote stack))) -(def: .public loop +(def .public loop (All (_ ,,,) (type.let [test (=> ,,, ,,, [Bit])] @@ -229,21 +229,21 @@ (loop [stack' pred]) stack')))) -(def: .public dip +(def .public dip (All (_ ,,, a) (=> ,,, [a (=> ,,, ,,,)] ,,, [a])) (function (_ [[stack a] quote]) [(quote stack) a])) -(def: .public dip_2 +(def .public dip_2 (All (_ ,,, a b) (=> ,,, [a b (=> ,,, ,,,)] ,,, [a b])) (function (_ [[[stack a] b] quote]) [[(quote stack) a] b])) -(def: .public do +(def .public do (All (_ ,,,0 ,,,1) (type.let [body (=> ,,,0 ,,,1) pred (=> ,,,1 ,,,0 [Bit])] @@ -252,7 +252,7 @@ (function (_ [[stack pred] body]) [[(body stack) pred] body])) -(def: .public while +(def .public while (All (_ ,,,0 ,,,1) (type.let [body (=> ,,,1 ,,,0) pred (=> ,,,0 ,,,1 [Bit])] @@ -264,21 +264,21 @@ (while [[(body stack') pred] body]) stack')))) -(def: .public compose +(def .public compose (All (_ ,,,0 ,,, ,,,1) (=> [(=> ,,,0 ,,,) (=> ,,, ,,,1)] [(=> ,,,0 ,,,1)])) (function (_ [[stack f] g]) [stack (|>> f g)])) -(def: .public partial +(def .public partial (All (_ ,,,0 ,,,1 a) (=> ,,,0 [a (=> ,,,0 [a] ,,,1)] ,,,0 [(=> ,,,0 ,,,1)])) (function (_ [[stack arg] quote]) [stack (|>> (push arg) quote)])) -(def: .public when +(def .public when (All (_ ,,,) (type.let [body (=> ,,, ,,,)] (=> ,,, [Bit body] @@ -288,7 +288,7 @@ (push ..drop) if)) -(def: .public ? +(def .public ? (All (_ a) (=> [Bit a a] [a])) (|>> left_rotation diff --git a/stdlib/source/library/lux/control/concurrency/actor.lux b/stdlib/source/library/lux/control/concurrency/actor.lux index 40bc65ec2..e67bb3f2b 100644 --- a/stdlib/source/library/lux/control/concurrency/actor.lux +++ b/stdlib/source/library/lux/control/concurrency/actor.lux @@ -31,7 +31,7 @@ [(Rec Mailbox [(Async [(<Mail> Actor s) Mailbox]) (Resolver [(<Mail> Actor s) Mailbox])])])] - (these (def: (pending [read write]) + (these (def (pending [read write]) (All (_ a) (-> (Rec Mailbox [(Async [a Mailbox]) @@ -62,7 +62,7 @@ (type: .public (Behavior s) (-> (Mail s) s (Actor s) (Async (Try s)))) - (def: .public (spawn! behavior init) + (def .public (spawn! behavior init) (All (_ s) (-> (Behavior s) s (IO (Actor s)))) (io (let [self (sharing [s] (is (Behavior s) @@ -88,7 +88,7 @@ (again state' tail))))] self))) - (def: .public (alive? actor) + (def .public (alive? actor) (All (_ s) (-> (Actor s) (IO Bit))) (let [[obituary _] (the #obituary (representation actor))] (|> obituary @@ -101,18 +101,18 @@ _ bit.no)))))) - (def: .public (obituary' actor) + (def .public (obituary' actor) (All (_ s) (-> (Actor s) (IO (Maybe (Obituary s))))) (let [[obituary _] (the #obituary (representation actor))] (async.value obituary))) - (def: .public obituary + (def .public obituary (All (_ s) (-> (Actor s) (Async (Obituary s)))) (|>> representation (the #obituary) product.left)) - (def: .public (mail! mail actor) + (def .public (mail! mail actor) (All (_ s) (-> (Mail s) (Actor s) (IO (Try Any)))) (do [! io.monad] [alive? (..alive? actor)] @@ -140,7 +140,7 @@ (type: .public (Message s o) (-> s (Actor s) (Async (Try [s o])))) - (def: (mail message) + (def (mail message) (All (_ s o) (-> (Message s o) [(Async (Try o)) (Mail s)])) (let [[async resolve] (sharing [s o] (is (Message s o) @@ -163,7 +163,7 @@ (io.run! (resolve {try.#Failure error})) (async.resolved {try.#Failure error})))))])) - (def: .public (tell! message actor) + (def .public (tell! message actor) (All (_ s o) (-> (Message s o) (Actor s) (Async (Try o)))) (let [[async mail] (..mail message)] (do async.monad @@ -176,12 +176,12 @@ (in {try.#Failure error}))))) ))) -(def: .public default +(def .public default Behavior (function (_ mail state self) (mail state self))) -(def: .public (poison! actor) +(def .public (poison! actor) (All (_ s) (-> (Actor s) (IO (Try Any)))) (..mail! (function (_ state self) (async.resolved (exception.except ..poisoned []))) @@ -190,10 +190,10 @@ (type: .public Stop (IO Any)) -(def: continue! true) -(def: stop! false) +(def continue! true) +(def stop! false) -(def: .public (observe! action channel actor) +(def .public (observe! action channel actor) (All (_ r w s) (-> (-> r Stop (Mail s)) (Channel' r w) (Actor s) (IO Any))) (let [signal (is (Atom Bit) (atom.atom ..continue!)) diff --git a/stdlib/source/library/lux/control/concurrency/async.lux b/stdlib/source/library/lux/control/concurrency/async.lux index 192c4e24c..11020adad 100644 --- a/stdlib/source/library/lux/control/concurrency/async.lux +++ b/stdlib/source/library/lux/control/concurrency/async.lux @@ -34,7 +34,7 @@ (-> w (IO Bit))) ... Sets an async's value if it has not been done yet. - (def: (resolver async) + (def (resolver async) (All (_ r w) (-> (Async' r w) (Resolver w))) (function (resolve value) (let [async (representation async)] @@ -54,23 +54,23 @@ (in #1)) (resolve value)))))))) - (def: .public (resolved value) + (def .public (resolved value) (All (_ a) (-> a (Async a))) (abstraction (atom [{.#Some (variance.write value)} (list)]))) - (def: .public (async _) + (def .public (async _) (All (_ r w) (-> Any [(Async' r w) (Resolver w)])) (let [async (abstraction (atom [{.#None} (list)]))] [async (..resolver async)])) - (def: .public value + (def .public value (All (_ r w) (-> (Async' r w) (IO (Maybe r)))) (|>> representation atom.read! (at io.functor each (|>> product.left (maybe#each (|>> variance.read)))))) - (def: .public (upon! f async) + (def .public (upon! f async) (All (_ r w) (-> (-> r (IO Any)) (Async' r w) (IO Any))) (do [! io.monad] [.let [async (representation async)] @@ -87,7 +87,7 @@ (upon! f (abstraction async))))))) ) -(def: .public resolved? +(def .public resolved? (All (_ r w) (-> (Async' r w) (IO Bit))) (|>> ..value (at io.functor each @@ -98,10 +98,10 @@ {.#Some _} #1))))) -(def: .public functor +(def .public functor (Functor Async) (implementation - (def: (each f fa) + (def (each f fa) (let [[fb resolve] (sharing [a b] (is (-> a b) f) @@ -111,12 +111,12 @@ (io.run! (..upon! (|>> f resolve) fa)) fb))))) -(def: .public apply +(def .public apply (Apply Async) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (let [[fb resolve] (sharing [a b] (is (Async (-> a b)) ff) @@ -128,14 +128,14 @@ ff)) fb))))) -(def: .public monad +(def .public monad (Monad Async) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: in ..resolved) + (def in ..resolved) - (def: (conjoint mma) + (def (conjoint mma) (let [[ma resolve] (sharing [a] (is (Async (Async a)) mma) @@ -145,7 +145,7 @@ (io.run! (..upon! (..upon! resolve) mma)) ma))))) -(def: .public (and left right) +(def .public (and left right) (All (_ lr lw rr rw) (-> (Async' lr lw) (Async' rr rw) (Async [lr rr]))) (let [[read! write!] (sharing [lr lw rr rw] (is [(Async' lr lw) (Async' rr rw)] @@ -159,7 +159,7 @@ left))] read!)) -(def: .public (or left right) +(def .public (or left right) (All (_ lr lw rr rw) (-> (Async' lr lw) (Async' rr rw) (Async (Or lr rr)))) (let [[left|right resolve] (sharing [lr lw rr rw] (is [(Async' lr lw) (Async' rr rw)] @@ -177,7 +177,7 @@ <sides> left|right)))) -(def: .public (either left right) +(def .public (either left right) (All (_ a lw rw) (-> (Async' a lw) (Async' a rw) (Async a))) (let [[left||right resolve] (sharing [a lw rw] (is [(Async' a lw) (Async' a rw)] @@ -192,7 +192,7 @@ [right])) left||right)))) -(def: .public (schedule! milli_seconds computation) +(def .public (schedule! milli_seconds computation) (All (_ a) (-> Nat (IO a) (Async a))) (let [[!out resolve] (sharing [a] (is (IO a) @@ -207,19 +207,19 @@ io.run!) !out))) -(def: .public future +(def .public future (All (_ a) (-> (IO a) (Async a))) (..schedule! 0)) -(def: .public (after milli_seconds value) +(def .public (after milli_seconds value) (All (_ a) (-> Nat a (Async a))) (..schedule! milli_seconds (io value))) -(def: .public (delay milli_seconds) +(def .public (delay milli_seconds) (-> Nat (Async Any)) (..after milli_seconds [])) -(def: .public (within milli_seconds async) +(def .public (within milli_seconds async) (All (_ r w) (-> Nat (Async' r w) (Async (Maybe r)))) (..or (..delay milli_seconds) async)) diff --git a/stdlib/source/library/lux/control/concurrency/atom.lux b/stdlib/source/library/lux/control/concurrency/atom.lux index 86399e1a6..e98479e10 100644 --- a/stdlib/source/library/lux/control/concurrency/atom.lux +++ b/stdlib/source/library/lux/control/concurrency/atom.lux @@ -38,7 +38,7 @@ (type: .public (Atom a) (Atom'' (Mutable a a))) - (def: .public (atom value) + (def .public (atom value) (All (_ a) (-> a (Atom a))) (abstraction (with_expansions [<jvm> (as_expected (java/util/concurrent/atomic/AtomicReference::new value))] @@ -46,14 +46,14 @@ @.jvm <jvm> (array.has! 0 (variance.write value) (array.empty 1)))))) - (def: .public (read! atom) + (def .public (read! atom) (All (_ r w) (-> (Atom' r w) (IO r))) (with_expansions [<jvm> (java/util/concurrent/atomic/AtomicReference::get (representation atom))] (io.io (for @.old (variance.read <jvm>) @.jvm <jvm> (variance.read (array.item 0 (representation atom))))))) - (def: .public (compare_and_swap! current new atom) + (def .public (compare_and_swap! current new atom) (All (_ r w) (-> r w (Atom' r w) (IO Bit))) (io.io (for @.old (ffi.of_boolean (java/util/concurrent/atomic/AtomicReference::compareAndSet (variance.write @@ -73,7 +73,7 @@ false)))) ) -(def: .public (update! f atom) +(def .public (update! f atom) (All (_ r w) (-> (-> r w) (Atom' r w) (IO [r w]))) (loop (again [_ []]) (do io.monad @@ -84,7 +84,7 @@ (in [old new]) (again []))))) -(def: .public (write! value atom) +(def .public (write! value atom) (All (_ r w) (-> w (Atom' r w) (IO r))) (|> atom (..update! (function.constant value)) diff --git a/stdlib/source/library/lux/control/concurrency/frp.lux b/stdlib/source/library/lux/control/concurrency/frp.lux index 43aae713f..16ef2927c 100644 --- a/stdlib/source/library/lux/control/concurrency/frp.lux +++ b/stdlib/source/library/lux/control/concurrency/frp.lux @@ -35,13 +35,13 @@ (is (-> w (IO (Try Any))) feed))) -(def: (sink resolution) +(def (sink resolution) (All (_ a) (-> (async.Resolver (Maybe [(Mutable a a) (Channel a)])) (Sink a))) (let [sink (atom.atom resolution)] (implementation - (def: close + (def close (loop (again [_ []]) (do [! io.monad] [current (atom.read! sink) @@ -58,7 +58,7 @@ ... Someone else fed the sink while I was closing it. (again []))))))) - (def: (feed value) + (def (feed value) (loop (again [_ []]) (do [! io.monad] [current (atom.read! sink) @@ -83,27 +83,27 @@ ... Someone else fed the sink. (again [])))))))))) -(def: .public (channel _) +(def .public (channel _) (All (_ a) (-> Any [(Channel a) (Sink a)])) (let [[async resolve] (async.async [])] [async (..sink resolve)])) -(def: .public functor +(def .public functor (Functor Channel) (implementation - (def: (each f) + (def (each f) (async#each (maybe#each (function (_ [head tail]) [(variance.write (f (variance.read head))) (each f tail)])))))) -(def: .public apply +(def .public apply (Apply Channel) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (do async.monad [item_f ff item_a fa] @@ -115,19 +115,19 @@ _ (in {.#None})))))) -(def: empty +(def empty Channel (async.resolved {.#None})) -(def: .public monad +(def .public monad (Monad Channel) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (in a) + (def (in a) (async.resolved {.#Some [(variance.write a) ..empty]})) - (def: (conjoint mma) + (def (conjoint mma) (let [[output sink] (sharing [a] (is (Channel (Channel a)) mma) @@ -161,7 +161,7 @@ (type: .public (Subscriber a) (-> a (IO (Maybe Any)))) -(def: .public (subscribe! subscriber channel) +(def .public (subscribe! subscriber channel) (All (_ r w) (-> (Subscriber r) (Channel' r w) (IO Any))) (io (exec (is (Async Any) @@ -181,7 +181,7 @@ (in []))))) []))) -(def: .public (only pass? channel) +(def .public (only pass? channel) (All (_ a) (-> (-> a Bit) (Channel a) (Channel a))) (do async.monad [item channel] @@ -195,13 +195,13 @@ {.#None} (in {.#None})))) -(def: .public (of_async async) +(def .public (of_async async) (All (_ a) (-> (Async a) (Channel a))) (async#each (function (_ value) {.#Some [(variance.write value) ..empty]}) async)) -(def: .public (mix f init channel) +(def .public (mix f init channel) (All (_ a b) (-> (-> b a (Async a)) a (Channel b) (Async a))) @@ -216,7 +216,7 @@ [init' (f (variance.read head) init)] (mix f init' tail))))) -(def: .public (mixes f init channel) +(def .public (mixes f init channel) (All (_ a b) (-> (-> b a (Async a)) a (Channel b) (Channel a))) @@ -234,7 +234,7 @@ [init' (f (variance.read head) init)] (mixes f init' tail)))))) -(def: .public (poll milli_seconds action) +(def .public (poll milli_seconds action) (All (_ a) (-> Nat (IO a) [(Channel a) (Sink a)])) (let [[output sink] (channel [])] @@ -246,11 +246,11 @@ (async.upon! again (async.delay milli_seconds))))) [output sink]))) -(def: .public (periodic milli_seconds) +(def .public (periodic milli_seconds) (-> Nat [(Channel Any) (Sink Any)]) (..poll milli_seconds (io []))) -(def: .public (iterations f init) +(def .public (iterations f init) (All (_ s o) (-> (-> s (Async (Maybe [s o]))) s (Channel o))) (do async.monad [?next (f init)] @@ -261,7 +261,7 @@ {.#None} {.#None})))) -(def: (distinct' equivalence previous channel) +(def (distinct' equivalence previous channel) (All (_ a) (-> (Equivalence a) a (Channel a) (Channel a))) (do async.monad [item channel] @@ -274,7 +274,7 @@ {.#None} (in {.#None})))) -(def: .public (distinct equivalence channel) +(def .public (distinct equivalence channel) (All (_ a) (-> (Equivalence a) (Channel a) (Channel a))) (do async.monad [item channel] @@ -285,7 +285,7 @@ {.#None} {.#None})))) -(def: .public (list channel) +(def .public (list channel) (All (_ a) (-> (Channel a) (Async (List a)))) (do [! async.monad] [item channel] @@ -297,7 +297,7 @@ {.#None} (in {.#End})))) -(def: .public (sequential milli_seconds values) +(def .public (sequential milli_seconds values) (All (_ a) (-> Nat (List a) (Channel a))) (case values {.#End} diff --git a/stdlib/source/library/lux/control/concurrency/semaphore.lux b/stdlib/source/library/lux/control/concurrency/semaphore.lux index 5cf050d4b..fbfacf228 100644 --- a/stdlib/source/library/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/library/lux/control/concurrency/semaphore.lux @@ -33,10 +33,10 @@ (primitive .public Semaphore (Atom State) - (def: most_positions_possible + (def most_positions_possible (.nat (at i.interval top))) - (def: .public (semaphore initial_open_positions) + (def .public (semaphore initial_open_positions) (-> Nat Semaphore) (let [max_positions (n.min initial_open_positions ..most_positions_possible)] @@ -44,7 +44,7 @@ #open_positions (.int max_positions) #waiting_list queue.empty])))) - (def: .public (wait! semaphore) + (def .public (wait! semaphore) (Ex (_ k) (-> Semaphore (Async Any))) (let [semaphore (representation semaphore) [signal sink] (is [(Async Any) (Resolver Any)] @@ -69,7 +69,7 @@ (exception.report "Max Positions" (%.nat max_positions))) - (def: .public (signal! semaphore) + (def .public (signal! semaphore) (Ex (_ k) (-> Semaphore (Async (Try Int)))) (let [semaphore (representation semaphore)] (async.future @@ -97,19 +97,19 @@ (primitive .public Mutex Semaphore - (def: .public (mutex _) + (def .public (mutex _) (-> Any Mutex) (abstraction (semaphore 1))) - (def: acquire! + (def acquire! (-> Mutex (Async Any)) (|>> representation ..wait!)) - (def: release! + (def release! (-> Mutex (Async (Try Int))) (|>> representation ..signal!)) - (def: .public (synchronize! mutex procedure) + (def .public (synchronize! mutex procedure) (All (_ a) (-> Mutex (IO (Async a)) (Async a))) (do async.monad [_ (..acquire! mutex) @@ -118,7 +118,7 @@ (in output))) ) -(def: .public limit +(def .public limit (refinement.refiner (n.> 0))) (type: .public Limit @@ -131,14 +131,14 @@ #start_turnstile Semaphore #end_turnstile Semaphore]) - (def: .public (barrier limit) + (def .public (barrier limit) (-> Limit Barrier) (abstraction [#limit limit #count (atom.atom 0) #start_turnstile (..semaphore 0) #end_turnstile (..semaphore 0)])) - (def: (un_block! times turnstile) + (def (un_block! times turnstile) (-> Nat Semaphore (Async Any)) (loop (again [step 0]) (if (n.< times step) @@ -148,7 +148,7 @@ (at async.monad in [])))) (with_template [<phase> <update> <goal> <turnstile>] - [(def: (<phase> barrier) + [(def (<phase> barrier) (-> Barrier (Async Any)) (do async.monad [.let [barrier (representation barrier) @@ -164,7 +164,7 @@ [end! -- 0 #end_turnstile] ) - (def: .public (block! barrier) + (def .public (block! barrier) (-> Barrier (Async Any)) (do async.monad [_ (..start! barrier)] diff --git a/stdlib/source/library/lux/control/concurrency/stm.lux b/stdlib/source/library/lux/control/concurrency/stm.lux index 2a0ae3956..87dd101c9 100644 --- a/stdlib/source/library/lux/control/concurrency/stm.lux +++ b/stdlib/source/library/lux/control/concurrency/stm.lux @@ -35,15 +35,15 @@ (type: .public (Var a) (Var'' (Mutable a a))) - (def: .public (var value) + (def .public (var value) (All (_ a) (-> a (Var a))) (abstraction (atom.atom [(variance.write value) (list)]))) - (def: read! + (def read! (All (_ r w) (-> (Var' r w) r)) (|>> representation atom.read! io.run! product.left variance.read)) - (def: (write! new_value var) + (def (write! new_value var) (All (_ r w) (-> w (Var' r w) (IO Any))) (do [! io.monad] [.let [var' (representation var)] @@ -70,7 +70,7 @@ (in [])) (write! new_value var)))) - (def: .public (changes target) + (def .public (changes target) (All (_ a) (-> (Var a) (IO [(Channel a) (Sink a)]))) (do io.monad [.let [[channel sink] (sharing [a] @@ -80,8 +80,8 @@ (frp.channel [])))] _ (atom.update! (function (_ [value observers]) [value {.#Item (implementation - (def: close (at sink close)) - (def: feed (|>> variance.read (at sink feed)))) + (def close (at sink close)) + (def feed (|>> variance.read (at sink feed)))) observers}]) (representation target))] (in [channel sink]))) @@ -99,7 +99,7 @@ (type: .public (STM a) (-> Tx [Tx a])) -(def: (var_value var tx) +(def (var_value var tx) (All (_ r w) (-> (Var' r w) Tx (Maybe r))) (|> tx (list.example (function (_ [_var _original _current]) @@ -109,7 +109,7 @@ _current)) as_expected)) -(def: .public (read var) +(def .public (read var) (All (_ r w) (-> (Var' r w) (STM r))) (function (_ tx) (case (var_value var tx) @@ -124,7 +124,7 @@ tx} value])))) -(def: (with_updated_var var value tx) +(def (with_updated_var var value tx) (All (_ r w) (-> (Var' r w) w Tx Tx)) (case tx {.#End} @@ -142,7 +142,7 @@ #current _current] (with_updated_var var value tx')}))) -(def: .public (write value var) +(def .public (write value var) (All (_ r w) (-> w (Var' r w) (STM Any))) (function (_ tx) (case (var_value var tx) @@ -157,40 +157,40 @@ tx} []]))) -(def: .public functor +(def .public functor (Functor STM) (implementation - (def: (each f fa) + (def (each f fa) (function (_ tx) (let [[tx' a] (fa tx)] [tx' (f a)]))))) -(def: .public apply +(def .public apply (Apply STM) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (function (_ tx) (let [[tx' f] (ff tx) [tx'' a] (fa tx')] [tx'' (f a)]))))) -(def: .public monad +(def .public monad (Monad STM) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (in a) + (def (in a) (function (_ tx) [tx a])) - (def: (conjoint mma) + (def (conjoint mma) (function (_ tx) (let [[tx' ma] (mma tx)] (ma tx')))))) -(def: .public (update f var) +(def .public (update f var) (All (_ r w) (-> (-> r w) (Var' r w) (STM [r w]))) (do ..monad [before (..read var) @@ -198,36 +198,36 @@ _ (..write after var)] (in [before after]))) -(def: (can_commit? tx) +(def (can_commit? tx) (-> Tx Bit) (list.every? (function (_ [_var _original _current]) (same? _original (..read! _var))) tx)) -(def: (commit_var! [_var _original _current]) +(def (commit_var! [_var _original _current]) (-> (Ex (_ r w) (Tx_Frame r w)) (IO Any)) (if (same? (as Any _original) (as Any _current)) (io []) (..write! _current _var))) -(def: fresh_tx Tx (list)) +(def fresh_tx Tx (list)) (type: (Commit a) [(STM a) (Async a) (Resolver a)]) -(def: pending_commits +(def pending_commits (Atom (Rec Commits [(Async [(Ex (_ a) (Commit a)) Commits]) (Resolver [(Ex (_ a) (Commit a)) Commits])])) (atom (async.async []))) -(def: commit_processor_flag +(def commit_processor_flag (Atom Bit) (atom #0)) -(def: (issue_commit! commit) +(def (issue_commit! commit) (All (_ a) (-> (Commit a) (IO Any))) (let [entry [commit (async.async [])]] (do [! io.monad] @@ -246,7 +246,7 @@ {.#Some [head tail]} (again tail))))))) -(def: (process_commit! commit) +(def (process_commit! commit) (All (_ a) (-> (Commit a) (IO Any))) (let [[stm_proc output resolve] commit [finished_tx value] (stm_proc fresh_tx)] @@ -256,7 +256,7 @@ (resolve value)) (..issue_commit! commit)))) -(def: start_commit_processor! +(def start_commit_processor! (IO Any) (do [! io.monad] [flag (atom.read! commit_processor_flag)] @@ -275,7 +275,7 @@ (in []))) ))) -(def: .public (commit! stm_proc) +(def .public (commit! stm_proc) (All (_ a) (-> (STM a) (Async a))) (let [[output resolver] (async.async [])] (exec diff --git a/stdlib/source/library/lux/control/concurrency/thread.lux b/stdlib/source/library/lux/control/concurrency/thread.lux index 4428f9daa..030e0c053 100644 --- a/stdlib/source/library/lux/control/concurrency/thread.lux +++ b/stdlib/source/library/lux/control/concurrency/thread.lux @@ -73,7 +73,7 @@ #action (IO Any)])) )) -(def: .public parallelism +(def .public parallelism Nat (with_expansions [<default> 1 <jvm> (<| (configuration.for ["lua_compiler?" ""] @@ -88,7 +88,7 @@ ... Default <default>))) -(with_expansions [<jvm> (these (def: runner +(with_expansions [<jvm> (these (def runner java/util/concurrent/ScheduledThreadPoolExecutor (|> ..parallelism .int @@ -100,14 +100,14 @@ @.python (these) ... Default - (these (def: started? + (these (def started? (Atom Bit) (atom.atom false)) - (def: runner + (def runner (Atom (List Thread)) (atom.atom (list)))))) -(def: (execute! action) +(def (execute! action) (-> (IO Any) Any) (case (try (io.run! action)) {try.#Failure error} @@ -120,7 +120,7 @@ {try.#Success _} [])) -(def: .public (schedule! milli_seconds action) +(def .public (schedule! milli_seconds action) (-> Nat (IO Any) (IO Any)) (with_expansions [<jvm> (let [runnable (ffi.object [] [java/lang/Runnable] [] @@ -163,7 +163,7 @@ ... https://en.wikipedia.org/wiki/Event_loop ... Starts the event-loop. - (def: .public run! + (def .public run! (IO Any) (do [! io.monad] [started? (atom.read! ..started?)] diff --git a/stdlib/source/library/lux/control/continuation.lux b/stdlib/source/library/lux/control/continuation.lux index 3cbd80b92..5c3ac3e9c 100644 --- a/stdlib/source/library/lux/control/continuation.lux +++ b/stdlib/source/library/lux/control/continuation.lux @@ -16,15 +16,15 @@ (type: .public (Cont i o) (-> (-> i o) o)) -(def: .public (continued next cont) +(def .public (continued next cont) (All (_ i o) (-> (-> i o) (Cont i o) o)) (cont next)) -(def: .public result +(def .public result (All (_ a) (-> (Cont a a) a)) (..continued function.identity)) -(def: .public (with_current f) +(def .public (with_current f) (All (_ a b z) (-> (-> (-> a (Cont b z)) (Cont a z)) @@ -33,17 +33,17 @@ (f (function (_ a) (function (_ _) (k a))) k))) -(def: .public pending +(def .public pending (syntax (_ [expr <code>.any]) (with_symbols [g!_ g!k] (in (list (` (.function ((~ g!_) (~ g!k)) ((~ g!k) (~ expr))))))))) -(def: .public (reset scope) +(def .public (reset scope) (All (_ i o) (-> (Cont i i) (Cont i o))) (function (_ k) (k (result scope)))) -(def: .public (shift f) +(def .public (shift f) (All (_ a) (-> (-> (-> a (Cont a a)) (Cont a a)) @@ -52,37 +52,37 @@ (f (function (_ a) (function (_ ic) (ic (oc a)))) function.identity))) -(def: .public functor +(def .public functor (All (_ o) (Functor (All (_ i) (Cont i o)))) (implementation - (def: (each f fv) + (def (each f fv) (function (_ k) (fv (function.composite k f)))))) -(def: .public apply +(def .public apply (All (_ o) (Apply (All (_ i) (Cont i o)))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fv ff) + (def (on fv ff) (function (_ k) (|> (k (f v)) (function (_ v)) fv (function (_ f)) ff))))) -(def: .public monad +(def .public monad (All (_ o) (Monad (All (_ i) (Cont i o)))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (in value) + (def (in value) (function (_ k) (k value))) - (def: (conjoint ffa) + (def (conjoint ffa) (function (_ k) (ffa (continued k)))))) -(def: .public (portal init) +(def .public (portal init) (All (_ i o z) (-> i (Cont [(-> i (Cont o z)) diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux index 81e46e66d..f80419c98 100644 --- a/stdlib/source/library/lux/control/exception.lux +++ b/stdlib/source/library/lux/control/exception.lux @@ -31,11 +31,11 @@ [#label Text #constructor (-> a Text)])) -(def: .public (match? exception error) +(def .public (match? exception error) (All (_ e) (-> (Exception e) Text Bit)) (text.starts_with? (the #label exception) error)) -(def: .public (when exception then try) +(def .public (when exception then try) (All (_ e a) (-> (Exception e) (-> Text a) (Try a) (Try a))) @@ -52,7 +52,7 @@ then)} {//.#Failure error})))) -(def: .public (otherwise else try) +(def .public (otherwise else try) (All (_ a) (-> (-> Text a) (Try a) a)) (case try @@ -62,21 +62,21 @@ {//.#Failure error} (else error))) -(def: .public (error exception message) +(def .public (error exception message) (All (_ e) (-> (Exception e) e Text)) ((the ..#constructor exception) message)) -(def: .public (except exception message) +(def .public (except exception message) (All (_ e a) (-> (Exception e) e (Try a))) {//.#Failure (..error exception message)}) -(def: .public (assertion exception message test) +(def .public (assertion exception message test) (All (_ e) (-> (Exception e) e Bit (Try Any))) (if test {//.#Success []} (..except exception message))) -(def: exception +(def exception (Parser [Code (List |type_variable|.Variable) [Text (List |input|.Input)] (Maybe Code)]) (let [private (is (Parser [(List |type_variable|.Variable) [Text (List |input|.Input)] (Maybe Code)]) (all <>.and @@ -90,14 +90,14 @@ (<>.and (<>#in (` .private)) private) ))) -(def: .public exception: +(def .public exception: (syntax (_ [[export_policy t_vars [name inputs] body] ..exception]) (macro.with_symbols [g!_ g!descriptor] (do meta.monad [current_module meta.current_module_name .let [descriptor (all text#composite "{" current_module "." name "}" text.new_line) g!self (code.local name)]] - (in (list (` (def: (~ export_policy) + (in (list (` (def (~ export_policy) (~ g!self) (All ((~ g!_) (~+ (list#each |type_variable|.format t_vars))) (..Exception [(~+ (list#each (the |input|.#type) inputs))])) @@ -107,7 +107,7 @@ ((~! text#composite) (~ g!descriptor) (~ (maybe.else (' "") body))))]))))))))) -(def: (report' entries) +(def (report' entries) (-> (List [Text Text]) Text) (let [header_separator ": " largest_header_size (list#mix (function (_ [header _] max) @@ -138,13 +138,13 @@ (on_entry head) tail)))) -(def: .public report +(def .public report (syntax (_ [entries (<>.many (<>.and <code>.any <code>.any))]) (in (list (` ((~! ..report') (list (~+ (|> entries (list#each (function (_ [header message]) (` [(~ header) (~ message)])))))))))))) -(def: .public (listing format entries) +(def .public (listing format entries) (All (_ a) (-> (-> a Text) (List a) Text)) (|> entries @@ -157,7 +157,7 @@ list.reversed ..report')) -(def: separator +(def separator (let [gap (all "lux text concat" text.new_line text.new_line) horizontal_line (|> "-" (list.repeated 64) text.together)] (all "lux text concat" @@ -165,14 +165,14 @@ horizontal_line gap))) -(def: (decorated prelude error) +(def (decorated prelude error) (-> Text Text Text) (all "lux text concat" prelude ..separator error)) -(def: .public (with exception message computation) +(def .public (with exception message computation) (All (_ e a) (-> (Exception e) e (Try a) (Try a))) (case computation {//.#Failure error} diff --git a/stdlib/source/library/lux/control/function.lux b/stdlib/source/library/lux/control/function.lux index 15cd56f93..bbf4969b3 100644 --- a/stdlib/source/library/lux/control/function.lux +++ b/stdlib/source/library/lux/control/function.lux @@ -4,31 +4,31 @@ [abstract [monoid (.only Monoid)]]]]) -(def: .public identity +(def .public identity (All (_ a) (-> a a)) (|>>)) -(def: .public (composite f g) +(def .public (composite f g) (All (_ a b c) (-> (-> b c) (-> a b) (-> a c))) (|>> g f)) -(def: .public (constant value) +(def .public (constant value) (All (_ o) (-> o (All (_ i) (-> i o)))) (function (_ _) value)) -(def: .public (flipped f) +(def .public (flipped f) (All (_ a b c) (-> (-> a b c) (-> b a c))) (function (_ x y) (f y x))) -(def: .public (on input function) +(def .public (on input function) (All (_ i o) (-> i (-> i o) o)) (function input)) -(def: .public monoid +(def .public monoid (All (_ a) (Monoid (-> a a))) (implementation - (def: identity ..identity) - (def: composite ..composite))) + (def identity ..identity) + (def composite ..composite))) diff --git a/stdlib/source/library/lux/control/function/contract.lux b/stdlib/source/library/lux/control/function/contract.lux index 753a90460..4bae3020d 100644 --- a/stdlib/source/library/lux/control/function/contract.lux +++ b/stdlib/source/library/lux/control/function/contract.lux @@ -24,13 +24,13 @@ [post_condition_failed] ) -(def: (assert! message test) +(def (assert! message test) (-> Text Bit []) (if test [] (panic! message))) -(def: .public pre +(def .public pre (syntax (_ [test <code>.any expr <code>.any]) (in (list (` (exec @@ -38,7 +38,7 @@ (~ test)) (~ expr))))))) -(def: .public post +(def .public post (syntax (_ [test <code>.any expr <code>.any]) (with_symbols [g!output] diff --git a/stdlib/source/library/lux/control/function/inline.lux b/stdlib/source/library/lux/control/function/inline.lux index e171f1f87..9481dd27c 100644 --- a/stdlib/source/library/lux/control/function/inline.lux +++ b/stdlib/source/library/lux/control/function/inline.lux @@ -15,11 +15,11 @@ [syntax (.only syntax) ["|[0]|" export]]]]]) -(def: declaration +(def declaration (Parser [Text (List Code)]) (<code>.form (<>.and <code>.local (<>.some <code>.any)))) -(def: inline +(def inline (Parser [Code [Text (List Code)] Code Code]) (|export|.parser (all <>.and @@ -28,7 +28,7 @@ <code>.any ))) -(def: .public inline: +(def .public inlined (syntax (_ [[privacy [name parameters] type term] ..inline]) (do [! meta.monad] [@ meta.current_module_name @@ -47,6 +47,6 @@ (list#each (function (_ parameter) (list parameter (` (~! <code>.any))))) list#conjoint)]] - (in (list (` (def: (~ privacy) (~ (code.local name)) + (in (list (` (def (~ privacy) (~ (code.local name)) ((~! syntax) ((~ (code.local name)) [(~+ g!parameters)]) (.at (~! meta.monad) (~' in) (.list (.`' (~ inlined)))))))))))) diff --git a/stdlib/source/library/lux/control/function/memo.lux b/stdlib/source/library/lux/control/function/memo.lux index 47ed679d5..60c464887 100644 --- a/stdlib/source/library/lux/control/function/memo.lux +++ b/stdlib/source/library/lux/control/function/memo.lux @@ -17,7 +17,7 @@ ["[0]" // ["[1]" mixin (.only Mixin Recursive)]]) -(def: .public memoization +(def .public memoization (All (_ i o) (Mixin i (State (Dictionary i o) o))) (function (_ delegate recur) @@ -37,7 +37,7 @@ (type: .public (Memo i o) (Recursive i (State (Dictionary i o) o))) -(def: .public (open memo) +(def .public (open memo) (All (_ i o) (type.let [Memory (Dictionary i o)] (-> (Memo i o) (-> [Memory i] [Memory o])))) @@ -45,14 +45,14 @@ (function (_ [memory input]) (|> input memo (state.result memory))))) -(def: .public (closed hash memo) +(def .public (closed hash memo) (All (_ i o) (-> (Hash i) (Memo i o) (-> i o))) (let [memo (//.fixed (//.mixed ..memoization (//.of_recursive memo))) empty (dictionary.empty hash)] (|>> memo (state.result empty) product.right))) -(def: .public (none hash memo) +(def .public (none hash memo) (All (_ i o) (-> (Hash i) (Memo i o) (-> i o))) (let [memo (//.fixed (//.of_recursive memo)) diff --git a/stdlib/source/library/lux/control/function/mixin.lux b/stdlib/source/library/lux/control/function/mixin.lux index d23e86e04..44796c733 100644 --- a/stdlib/source/library/lux/control/function/mixin.lux +++ b/stdlib/source/library/lux/control/function/mixin.lux @@ -12,42 +12,42 @@ (type: .public (Mixin i o) (-> (-> i o) (-> i o) (-> i o))) -(def: .public (fixed f) +(def .public (fixed f) (All (_ i o) (-> (Mixin i o) (-> i o))) (function (mix input) ((f mix mix) input))) -(def: .public nothing +(def .public nothing Mixin (function (_ delegate recur) delegate)) -(def: .public (mixed parent child) +(def .public (mixed parent child) (All (_ i o) (-> (Mixin i o) (Mixin i o) (Mixin i o))) (function (_ delegate recur) (parent (child delegate recur) recur))) -(def: .public monoid +(def .public monoid (All (_ i o) (Monoid (Mixin i o))) (implementation - (def: identity ..nothing) - (def: composite ..mixed))) + (def identity ..nothing) + (def composite ..mixed))) -(def: .public (advice when then) +(def .public (advice when then) (All (_ i o) (-> (Predicate i) (Mixin i o) (Mixin i o))) (function (_ delegate recur input) (if (when input) ((then delegate recur) input) (delegate input)))) -(def: .public (before monad action) +(def .public (before monad action) (All (_ ! i o) (-> (Monad !) (-> i (! Any)) (Mixin i (! o)))) (function (_ delegate recur input) (do monad [_ (action input)] (delegate input)))) -(def: .public (after monad action) +(def .public (after monad action) (All (_ ! i o) (-> (Monad !) (-> i o (! Any)) (Mixin i (! o)))) (function (_ delegate recur input) (do monad @@ -58,7 +58,7 @@ (type: .public (Recursive i o) (-> (-> i o) (-> i o))) -(def: .public (of_recursive recursive) +(def .public (of_recursive recursive) (All (_ i o) (-> (Recursive i o) (Mixin i o))) (function (_ delegate recur) (recursive recur))) diff --git a/stdlib/source/library/lux/control/function/mutual.lux b/stdlib/source/library/lux/control/function/mutual.lux index bdf3fbde9..d0b03aa08 100644 --- a/stdlib/source/library/lux/control/function/mutual.lux +++ b/stdlib/source/library/lux/control/function/mutual.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except Definition let def: macro) + [lux (.except Definition let def macro) ["[0]" meta] [abstract ["[0]" monad (.only do)]] @@ -30,7 +30,7 @@ #type Code #body Code])) -(.def: mutual +(.def mutual (Parser [Declaration Code Code]) (all <>.and declaration.parser @@ -38,21 +38,21 @@ <code>.any )) -(.def: (mutual_definition context g!context [g!name mutual]) +(.def (mutual_definition context g!context [g!name mutual]) (-> (List Code) Code [Code Mutual] Code) (` (function ((~ g!name) (~ g!context)) (.let [[(~+ context)] (~ g!context)] (function (~ (declaration.format (the #declaration mutual))) (~ (the #body mutual))))))) -(.def: (macro g!context g!self) +(.def (macro g!context g!self) (-> Code Code Macro) (<| (as Macro) (is Macro') (function (_ parameters) (at meta.monad in (list (` (((~ g!self) (~ g!context)) (~+ parameters)))))))) -(.def: .public let +(.def .public let (syntax (_ [functions (<code>.tuple (<>.some ..mutual)) body <code>.any]) (case functions @@ -101,12 +101,12 @@ [#export_policy Code #mutual Mutual])) -(.def: definition +(.def definition (Parser Definition) (<code>.tuple (<>.either (<>.and <code>.any ..mutual) (<>.and (<>#in (` .private)) ..mutual)))) -(.def: .public def: +(.def .public def (syntax (_ [functions (<>.many ..definition)]) (case functions {.#End} @@ -115,7 +115,7 @@ {.#Item definition {.#End}} (.let [(open "_[0]") definition (open "_[0]") _#mutual] - (in (list (` (.def: (~ _#export_policy) (~ (declaration.format _#declaration)) + (in (list (` (.def (~ _#export_policy) (~ (declaration.format _#declaration)) (~ _#type) (~ _#body)))))) @@ -138,7 +138,7 @@ (..macro g!context g!name)]) (list.zipped_2 hidden_names functions)))] - (in (list.partial (` (.def: (~ g!context) + (in (list.partial (` (.def (~ g!context) [(~+ (list#each (the [#mutual #type]) functions))] (.let [(~ g!context) (is (Rec (~ g!context) [(~+ context_types)]) @@ -150,7 +150,7 @@ g!pop (list#each (function (_ mutual) (.let [g!name (|> mutual (the [#mutual #declaration declaration.#name]) code.local)] - (` (.def: + (` (.def (~ (the #export_policy mutual)) (~ g!name) (~ (the [#mutual #type] mutual)) diff --git a/stdlib/source/library/lux/control/io.lux b/stdlib/source/library/lux/control/io.lux index 0b2372c6b..fecb0ee7b 100644 --- a/stdlib/source/library/lux/control/io.lux +++ b/stdlib/source/library/lux/control/io.lux @@ -17,54 +17,54 @@ (primitive .public (IO a) (-> Any a) - (def: label + (def label (All (_ a) (-> (-> Any a) (IO a))) (|>> abstraction)) - (def: !io + (def !io (template (!io computation) [(abstraction (template.with_locals [g!func g!arg] (function (g!func g!arg) computation)))])) - (def: run!' + (def run!' (template (run!' io) ... creatio ex nihilo [((representation io) [])])) - (def: .public io + (def .public io (syntax (_ [computation <code>.any]) (with_symbols [g!func g!arg] (in (list (` ((~! ..label) (function ((~ g!func) (~ g!arg)) (~ computation))))))))) - (def: .public run! + (def .public run! (All (_ a) (-> (IO a) a)) (|>> ..run!')) - (def: .public functor + (def .public functor (Functor IO) (implementation - (def: (each f) + (def (each f) (|>> ..run!' f !io)))) - (def: .public apply + (def .public apply (Apply IO) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (!io ((..run!' ff) (..run!' fa)))))) - (def: .public monad + (def .public monad (Monad IO) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: in + (def in (|>> !io)) - (def: conjoint + (def conjoint (|>> ..run!' ..run!' !io)))) ) diff --git a/stdlib/source/library/lux/control/lazy.lux b/stdlib/source/library/lux/control/lazy.lux index 343f866f7..50f18e0dd 100644 --- a/stdlib/source/library/lux/control/lazy.lux +++ b/stdlib/source/library/lux/control/lazy.lux @@ -20,7 +20,7 @@ (primitive .public (Lazy a) (-> [] a) - (def: (lazy' generator) + (def (lazy' generator) (All (_ a) (-> (-> [] a) (Lazy a))) (let [cache (atom.atom (sharing [a] (is (-> [] a) @@ -38,38 +38,38 @@ (io.run! (atom.compare_and_swap! _ {.#Some value} cache)) value))))))) - (def: .public (value lazy) + (def .public (value lazy) (All (_ a) (-> (Lazy a) a)) ((representation lazy) []))) -(def: .public lazy +(def .public lazy (syntax (_ [expression <code>.any]) (with_symbols [g!_] (in (list (` ((~! ..lazy') (function ((~ g!_) (~ g!_)) (~ expression))))))))) -(def: .public (equivalence (open "_#[0]")) +(def .public (equivalence (open "_#[0]")) (All (_ a) (-> (Equivalence a) (Equivalence (Lazy a)))) (implementation - (def: (= left right) + (def (= left right) (_#= (..value left) (..value right))))) -(def: .public functor +(def .public functor (Functor Lazy) (implementation - (def: (each f fa) + (def (each f fa) (lazy (f (value fa)))))) -(def: .public apply +(def .public apply (Apply Lazy) (implementation - (def: functor ..functor) - (def: (on fa ff) + (def functor ..functor) + (def (on fa ff) (lazy ((value ff) (value fa)))))) -(def: .public monad +(def .public monad (Monad Lazy) (implementation - (def: functor ..functor) - (def: in (|>> lazy)) - (def: conjoint ..value))) + (def functor ..functor) + (def in (|>> lazy)) + (def conjoint ..value))) diff --git a/stdlib/source/library/lux/control/maybe.lux b/stdlib/source/library/lux/control/maybe.lux index 00cef670e..b138ab65c 100644 --- a/stdlib/source/library/lux/control/maybe.lux +++ b/stdlib/source/library/lux/control/maybe.lux @@ -15,13 +15,13 @@ ... {.#None} ... {.#Some a}) -(def: .public monoid +(def .public monoid (All (_ a) (Monoid (Maybe a))) (implementation - (def: identity + (def identity {.#None}) - (def: (composite mx my) + (def (composite mx my) (case mx {.#None} my @@ -29,10 +29,10 @@ _ mx)))) -(def: .public functor +(def .public functor (Functor Maybe) (implementation - (def: (each f ma) + (def (each f ma) (case ma {.#Some a} {.#Some (f a)} @@ -41,12 +41,12 @@ it (as_expected it))))) -(def: .public apply +(def .public apply (Apply Maybe) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (case [ff fa] [{.#Some f} {.#Some a}] {.#Some (f a)} @@ -54,15 +54,15 @@ _ {.#None})))) -(def: .public monad +(def .public monad (Monad Maybe) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (in x) + (def (in x) {.#Some x}) - (def: (conjoint mma) + (def (conjoint mma) (case mma {.#Some mx} mx @@ -71,10 +71,10 @@ it (as_expected it))))) -(def: .public (equivalence super) +(def .public (equivalence super) (All (_ a) (-> (Equivalence a) (Equivalence (Maybe a)))) (implementation - (def: (= mx my) + (def (= mx my) (case [mx my] [{.#None} {.#None}] #1 @@ -85,13 +85,13 @@ _ #0)))) -(def: .public (hash super) +(def .public (hash super) (All (_ a) (-> (Hash a) (Hash (Maybe a)))) (implementation - (def: equivalence + (def equivalence (..equivalence (at super equivalence))) - (def: (hash value) + (def (hash value) (case value {.#None} 1 @@ -99,18 +99,18 @@ {.#Some value} (at super hash value))))) -(def: .public (with monad) +(def .public (with monad) (All (_ M) (-> (Monad M) (Monad (All (_ a) (M (Maybe a)))))) (implementation - (def: functor + (def functor (functor.composite (the monad.functor monad) ..functor)) - (def: in + (def in (|>> (at ..monad in) (at monad in))) - (def: (conjoint MmMma) + (def (conjoint MmMma) (do monad [mMma MmMma] (case mMma @@ -121,11 +121,11 @@ it (in (as_expected it))))))) -(def: .public (lifted monad) +(def .public (lifted monad) (All (_ M a) (-> (Monad M) (-> (M a) (M (Maybe a))))) (at monad each (at ..monad in))) -(def: .public else +(def .public else (macro (_ tokens state) (case tokens (pattern (.list else maybe)) @@ -141,11 +141,11 @@ _ {.#Left "Wrong syntax for 'else'"}))) -(def: .public trusted +(def .public trusted (All (_ a) (-> (Maybe a) a)) (|>> (..else (undefined)))) -(def: .public (list value) +(def .public (list value) (All (_ a) (-> (Maybe a) (List a))) (case value {.#Some value} @@ -155,7 +155,7 @@ _ (.list))) -(def: .public when +(def .public when (macro (_ tokens state) (case tokens (pattern (.list test then)) diff --git a/stdlib/source/library/lux/control/parser.lux b/stdlib/source/library/lux/control/parser.lux index fef41832d..1c402df83 100644 --- a/stdlib/source/library/lux/control/parser.lux +++ b/stdlib/source/library/lux/control/parser.lux @@ -19,10 +19,10 @@ (type: .public (Parser s a) (-> s (Try [s a]))) -(def: .public functor +(def .public functor (All (_ s) (Functor (Parser s))) (implementation - (def: (each f ma) + (def (each f ma) (function (_ input) (case (ma input) {try.#Success [input' a]} @@ -31,12 +31,12 @@ {try.#Failure msg} {try.#Failure msg}))))) -(def: .public apply +(def .public apply (All (_ s) (Apply (Parser s))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (function (_ input) (case (ff input) {try.#Success [input' f]} @@ -50,16 +50,16 @@ {try.#Failure msg} {try.#Failure msg}))))) -(def: .public monad +(def .public monad (All (_ s) (Monad (Parser s))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (in x) + (def (in x) (function (_ input) {try.#Success [input x]})) - (def: (conjoint mma) + (def (conjoint mma) (function (_ input) (case (mma input) {try.#Success [input' ma]} @@ -68,14 +68,14 @@ {try.#Failure msg} {try.#Failure msg}))))) -(def: .public (assertion message test) +(def .public (assertion message test) (All (_ s) (-> Text Bit (Parser s Any))) (function (_ input) (if test {try.#Success [input []]} {try.#Failure message}))) -(def: .public (maybe parser) +(def .public (maybe parser) (All (_ s a) (-> (Parser s a) (Parser s (Maybe a)))) (function (_ input) @@ -86,19 +86,19 @@ {try.#Failure _} {try.#Success [input {.#None}]}))) -(def: .public (result parser input) +(def .public (result parser input) (All (_ s a) (-> (Parser s a) s (Try [s a]))) (parser input)) -(def: .public (and first second) +(def .public (and first second) (All (_ s a b) (-> (Parser s a) (Parser s b) (Parser s [a b]))) (do [! ..monad] [head first] (at ! each (|>> [head]) second))) -(def: .public (or left right) +(def .public (or left right) (All (_ s a b) (-> (Parser s a) (Parser s b) (Parser s (Or a b)))) (function (_ tokens) @@ -114,7 +114,7 @@ {try.#Failure error} {try.#Failure error})))) -(def: .public (either this that) +(def .public (either this that) (All (_ s a) (-> (Parser s a) (Parser s a) (Parser s a))) (function (_ tokens) @@ -125,7 +125,7 @@ output output))) -(def: .public (some parser) +(def .public (some parser) (All (_ s a) (-> (Parser s a) (Parser s (List a)))) (function (_ input) @@ -138,14 +138,14 @@ {try.#Failure _} {try.#Success [input (list)]}))) -(def: .public (many parser) +(def .public (many parser) (All (_ s a) (-> (Parser s a) (Parser s (List a)))) (|> (..some parser) (..and parser) (at ..monad each (|>> {.#Item})))) -(def: .public (exactly amount parser) +(def .public (exactly amount parser) (All (_ s a) (-> Nat (Parser s a) (Parser s (List a)))) (case amount 0 (at ..monad in (list)) @@ -155,13 +155,13 @@ (exactly (-- amount)) (at ! each (|>> {.#Item x})))))) -(def: .public (at_least amount parser) +(def .public (at_least amount parser) (All (_ s a) (-> Nat (Parser s a) (Parser s (List a)))) (do [! ..monad] [minimum (..exactly amount parser)] (at ! each (list#composite minimum) (..some parser)))) -(def: .public (at_most amount parser) +(def .public (at_most amount parser) (All (_ s a) (-> Nat (Parser s a) (Parser s (List a)))) (case amount 0 (at ..monad in (list)) @@ -175,7 +175,7 @@ {try.#Failure msg} {try.#Success [input (list)]})))) -(def: .public (between minimum additional parser) +(def .public (between minimum additional parser) (All (_ s a) (-> Nat Nat (Parser s a) (Parser s (List a)))) (do [! ..monad] [minimum (..exactly minimum parser)] @@ -184,7 +184,7 @@ _ (at ! each (list#composite minimum) (..at_most additional parser))))) -(def: .public (separated_by separator parser) +(def .public (separated_by separator parser) (All (_ s a b) (-> (Parser s b) (Parser s a) (Parser s (List a)))) (do [! ..monad] [?x (..maybe parser)] @@ -198,7 +198,7 @@ {.#None} (in {.#End})))) -(def: .public (not parser) +(def .public (not parser) (All (_ s a) (-> (Parser s a) (Parser s Any))) (function (_ input) (case (parser input) @@ -208,12 +208,12 @@ _ {try.#Failure "Expected to fail; yet succeeded."}))) -(def: .public (failure message) +(def .public (failure message) (All (_ s a) (-> Text (Parser s a))) (function (_ input) {try.#Failure message})) -(def: .public (lifted operation) +(def .public (lifted operation) (All (_ s a) (-> (Try a) (Parser s a))) (function (_ input) (case operation @@ -223,7 +223,7 @@ {try.#Failure error} {try.#Failure error}))) -(def: .public (else value parser) +(def .public (else value parser) (All (_ s a) (-> a (Parser s a) (Parser s a))) (function (_ input) (case (parser input) @@ -233,37 +233,37 @@ {try.#Failure error} {try.#Success [input value]}))) -(def: .public remaining +(def .public remaining (All (_ s) (Parser s s)) (function (_ inputs) {try.#Success [inputs inputs]})) -(def: .public (rec parser) +(def .public (rec parser) (All (_ s a) (-> (-> (Parser s a) (Parser s a)) (Parser s a))) (function (_ inputs) (..result (parser (rec parser)) inputs))) -(def: .public (after param subject) +(def .public (after param subject) (All (_ s _ a) (-> (Parser s _) (Parser s a) (Parser s a))) (do ..monad [_ param] subject)) -(def: .public (before param subject) +(def .public (before param subject) (All (_ s _ a) (-> (Parser s _) (Parser s a) (Parser s a))) (do ..monad [output subject _ param] (in output))) -(def: .public (only test parser) +(def .public (only test parser) (All (_ s a) (-> (-> a Bit) (Parser s a) (Parser s a))) (do ..monad [output parser _ (..assertion "Constraint failed." (test output))] (in output))) -(def: .public (parses? parser) +(def .public (parses? parser) (All (_ s a) (-> (Parser s a) (Parser s Bit))) (function (_ input) (case (parser input) @@ -273,7 +273,7 @@ {try.#Failure error} {try.#Success [input false]}))) -(def: .public (parses parser) +(def .public (parses parser) (All (_ s a) (-> (Parser s a) (Parser s Any))) (function (_ input) (case (parser input) @@ -283,7 +283,7 @@ {try.#Failure error} {try.#Failure error}))) -(def: .public (speculative parser) +(def .public (speculative parser) (All (_ s a) (-> (Parser s a) (Parser s a))) (function (_ input) (case (parser input) @@ -293,7 +293,7 @@ failure failure))) -(def: .public (codec codec parser) +(def .public (codec codec parser) (All (_ s a z) (-> (Codec a z) (Parser s a) (Parser s z))) (function (_ input) (case (parser input) diff --git a/stdlib/source/library/lux/control/parser/cli.lux b/stdlib/source/library/lux/control/parser/cli.lux index 89ea21893..b00698644 100644 --- a/stdlib/source/library/lux/control/parser/cli.lux +++ b/stdlib/source/library/lux/control/parser/cli.lux @@ -13,7 +13,7 @@ (type: .public (Parser a) (//.Parser (List Text) a)) -(def: .public (result parser inputs) +(def .public (result parser inputs) (All (_ a) (-> (Parser a) (List Text) (Try a))) (case (//.result parser inputs) {try.#Success [remaining output]} @@ -27,7 +27,7 @@ {try.#Failure try} {try.#Failure try})) -(def: .public any +(def .public any (Parser Text) (function (_ inputs) (case inputs @@ -37,7 +37,7 @@ _ {try.#Failure "Cannot parse empty arguments."}))) -(def: .public (parse parser) +(def .public (parse parser) (All (_ a) (-> (-> Text (Try a)) (Parser a))) (function (_ inputs) (do try.monad @@ -45,7 +45,7 @@ output (parser raw)] (in [remaining output])))) -(def: .public (this reference) +(def .public (this reference) (-> Text (Parser Any)) (function (_ inputs) (do try.monad @@ -54,7 +54,7 @@ (in [remaining []]) {try.#Failure (format "Missing token: '" reference "'")})))) -(def: .public (somewhere cli) +(def .public (somewhere cli) (All (_ a) (-> (Parser a) (Parser a))) (function (_ inputs) (loop (again [immediate inputs]) @@ -73,20 +73,20 @@ (in [{.#Item to_omit remaining} output]))))))) -(def: .public end +(def .public end (Parser Any) (function (_ inputs) (case inputs {.#End} {try.#Success [inputs []]} _ {try.#Failure (format "Unknown parameters: " (text.interposed " " inputs))}))) -(def: .public (named name value) +(def .public (named name value) (All (_ a) (-> Text (Parser a) (Parser a))) (|> value (//.after (..this name)) ..somewhere)) -(def: .public (parameter [short long] value) +(def .public (parameter [short long] value) (All (_ a) (-> [Text Text] (Parser a) (Parser a))) (|> value (//.after (//.either (..this short) (..this long))) diff --git a/stdlib/source/library/lux/control/parser/code.lux b/stdlib/source/library/lux/control/parser/code.lux index abdcb7075..337201593 100644 --- a/stdlib/source/library/lux/control/parser/code.lux +++ b/stdlib/source/library/lux/control/parser/code.lux @@ -22,7 +22,7 @@ ["[0]" symbol]]]] ["[0]" //]) -(def: (un_paired pairs) +(def (un_paired pairs) (All (_ a) (-> (List [a a]) (List a))) (case pairs {.#End} @@ -34,13 +34,13 @@ (type: .public Parser (//.Parser (List Code))) -(def: remaining_inputs +(def remaining_inputs (-> (List Code) Text) (|>> (list#each code.format) (text.interposed " ") (all text#composite text.new_line "Remaining input: "))) -(def: .public any +(def .public any (Parser Code) (function (_ tokens) (case tokens @@ -50,7 +50,7 @@ {.#Item [t tokens']} {try.#Success [tokens' t]}))) -(def: .public next +(def .public next (Parser Code) (function (_ tokens) (case tokens @@ -62,7 +62,7 @@ (with_template [<query> <check> <type> <tag> <eq> <desc>] [(with_expansions [<failure> (these {try.#Failure (all text#composite "Cannot parse " <desc> (remaining_inputs tokens))})] - (def: .public <query> + (def .public <query> (Parser <type>) (function (_ tokens) (case tokens @@ -72,7 +72,7 @@ _ <failure>))) - (def: .public (<check> expected) + (def .public (<check> expected) (-> <type> (Parser Any)) (function (_ tokens) (case tokens @@ -93,7 +93,7 @@ [symbol this_symbol Symbol .#Symbol symbol.equivalence "symbol"] ) -(def: .public (this code) +(def .public (this code) (-> Code (Parser Any)) (function (_ tokens) (case tokens @@ -107,7 +107,7 @@ {try.#Failure "There are no tokens to parse!"}))) (with_expansions [<failure> (these {try.#Failure (all text#composite "Cannot parse local symbol" (remaining_inputs tokens))})] - (def: .public local + (def .public local (Parser Text) (function (_ tokens) (case tokens @@ -117,7 +117,7 @@ _ <failure>))) - (def: .public (this_local expected) + (def .public (this_local expected) (-> Text (Parser Any)) (function (_ tokens) (case tokens @@ -130,7 +130,7 @@ <failure>)))) (with_expansions [<failure> (these {try.#Failure (all text#composite "Cannot parse local symbol" (remaining_inputs tokens))})] - (def: .public global + (def .public global (Parser Symbol) (function (_ tokens) (case tokens @@ -143,7 +143,7 @@ _ <failure>))) - (def: .public (this_global expected) + (def .public (this_global expected) (-> Symbol (Parser Any)) (function (_ tokens) (case tokens @@ -159,7 +159,7 @@ <failure>)))) (with_template [<name> <tag> <desc>] - [(def: .public (<name> p) + [(def .public (<name> p) (All (_ a) (-> (Parser a) (Parser a))) (function (_ tokens) @@ -177,21 +177,21 @@ [tuple .#Tuple "tuple"] ) -(def: .public end +(def .public end (Parser Any) (function (_ tokens) (case tokens {.#End} {try.#Success [tokens []]} _ {try.#Failure (all text#composite "Expected list of tokens to be empty!" (remaining_inputs tokens))}))) -(def: .public end? +(def .public end? (Parser Bit) (function (_ tokens) {try.#Success [tokens (case tokens {.#End} true _ false)]})) -(def: .public (result parser inputs) +(def .public (result parser inputs) (All (_ a) (-> (Parser a) (List Code) (Try a))) (case (parser inputs) {try.#Failure error} @@ -208,14 +208,14 @@ (text.interposed ", ") (text#composite "Unconsumed inputs: "))}))) -(def: .public (locally inputs parser) +(def .public (locally inputs parser) (All (_ a) (-> (List Code) (Parser a) (Parser a))) (function (_ real) (do try.monad [value (..result parser inputs)] (in [real value])))) -(def: .public (not parser) +(def .public (not parser) (All (_ a) (-> (Parser a) (Parser Code))) (do //.monad [sample ..next diff --git a/stdlib/source/library/lux/control/parser/environment.lux b/stdlib/source/library/lux/control/parser/environment.lux index b6a669a56..601cd9a5d 100644 --- a/stdlib/source/library/lux/control/parser/environment.lux +++ b/stdlib/source/library/lux/control/parser/environment.lux @@ -25,11 +25,11 @@ (type: .public (Parser a) (//.Parser Environment a)) -(def: .public empty +(def .public empty Environment (dictionary.empty text.hash)) -(def: .public (property name) +(def .public (property name) (-> Property (Parser Text)) (function (_ environment) (case (dictionary.value name environment) @@ -39,6 +39,6 @@ {.#None} (exception.except ..unknown_property [name])))) -(def: .public (result parser environment) +(def .public (result parser environment) (All (_ a) (-> (Parser a) Environment (Try a))) (at try.monad each product.right (parser environment))) diff --git a/stdlib/source/library/lux/control/parser/json.lux b/stdlib/source/library/lux/control/parser/json.lux index 8f7fe459f..308c8c918 100644 --- a/stdlib/source/library/lux/control/parser/json.lux +++ b/stdlib/source/library/lux/control/parser/json.lux @@ -31,7 +31,7 @@ (exception: .public empty_input) -(def: .public (result parser json) +(def .public (result parser json) (All (_ a) (-> (Parser a) JSON (Try a))) (case (//.result parser (list json)) {try.#Success [remainder output]} @@ -45,7 +45,7 @@ {try.#Failure error} {try.#Failure error})) -(def: .public any +(def .public any (Parser JSON) (<| (function (_ inputs)) (case inputs @@ -60,7 +60,7 @@ "Value" (/.format value))) (with_template [<name> <type> <tag>] - [(def: .public <name> + [(def .public <name> (Parser <type>) (do //.monad [head ..any] @@ -84,7 +84,7 @@ "Sample" (/.format sample))) (with_template [<test> <check> <type> <equivalence> <tag>] - [(def: .public (<test> test) + [(def .public (<test> test) (-> <type> (Parser Bit)) (do //.monad [head ..any] @@ -95,7 +95,7 @@ _ (//.failure (exception.error ..unexpected_value [head]))))) - (def: .public (<check> test) + (def .public (<check> test) (-> <type> (Parser Any)) (do //.monad [head ..any] @@ -113,12 +113,12 @@ [string? this_string /.String text.equivalence /.#String] ) -(def: .public (nullable parser) +(def .public (nullable parser) (All (_ a) (-> (Parser a) (Parser (Maybe a)))) (//.or ..null parser)) -(def: .public (array parser) +(def .public (array parser) (All (_ a) (-> (Parser a) (Parser a))) (do //.monad [head ..any] @@ -139,7 +139,7 @@ _ (//.failure (exception.error ..unexpected_value [head]))))) -(def: .public (object parser) +(def .public (object parser) (All (_ a) (-> (Parser a) (Parser a))) (do //.monad [head ..any] @@ -165,7 +165,7 @@ _ (//.failure (exception.error ..unexpected_value [head]))))) -(def: .public (field field_name parser) +(def .public (field field_name parser) (All (_ a) (-> Text (Parser a) (Parser a))) (function (again inputs) (case inputs @@ -191,7 +191,7 @@ _ (exception.except ..unconsumed_input inputs)))) -(def: .public dictionary +(def .public dictionary (All (_ a) (-> (Parser a) (Parser (Dictionary Text a)))) (|>> (//.and ..string) //.some diff --git a/stdlib/source/library/lux/control/parser/tree.lux b/stdlib/source/library/lux/control/parser/tree.lux index 751d370db..b7a37f0ef 100644 --- a/stdlib/source/library/lux/control/parser/tree.lux +++ b/stdlib/source/library/lux/control/parser/tree.lux @@ -15,17 +15,17 @@ (type: .public (Parser t a) (//.Parser (Zipper t) a)) -(def: .public (result' parser zipper) +(def .public (result' parser zipper) (All (_ t a) (-> (Parser t a) (Zipper t) (Try a))) (do try.monad [[zipper output] (//.result parser zipper)] (in output))) -(def: .public (result parser tree) +(def .public (result parser tree) (All (_ t a) (-> (Parser t a) (Tree t) (Try a))) (result' parser (zipper.zipper tree))) -(def: .public value +(def .public value (All (_ t) (Parser t t)) (function (_ zipper) {try.#Success [zipper (zipper.value zipper)]})) @@ -33,7 +33,7 @@ (exception: .public cannot_move_further) (with_template [<name> <direction>] - [(def: .public <name> + [(def .public <name> (All (_ t) (Parser t [])) (function (_ zipper) (case (<direction> zipper) diff --git a/stdlib/source/library/lux/control/parser/type.lux b/stdlib/source/library/lux/control/parser/type.lux index 1b8a9de5a..cff760d80 100644 --- a/stdlib/source/library/lux/control/parser/type.lux +++ b/stdlib/source/library/lux/control/parser/type.lux @@ -23,7 +23,7 @@ ["[0]" check]]]] ["[0]" //]) -(def: |recursion_dummy| +(def |recursion_dummy| (template (|recursion_dummy|) [{.#Primitive "" {.#End}}])) @@ -69,11 +69,11 @@ (type: .public (Parser a) (//.Parser [Env (List Type)] a)) -(def: .public fresh +(def .public fresh Env (dictionary.empty n.hash)) -(def: (result' env poly types) +(def (result' env poly types) (All (_ a) (-> Env (Parser a) (List Type) (Try a))) (case (//.result poly [env types]) {try.#Failure error} @@ -87,16 +87,16 @@ _ (exception.except ..unconsumed_input remaining)))) -(def: .public (result poly type) +(def .public (result poly type) (All (_ a) (-> (Parser a) Type (Try a))) (result' ..fresh poly (list type))) -(def: .public env +(def .public env (Parser Env) (.function (_ [env inputs]) {try.#Success [[env inputs] env]})) -(def: (with_env temp poly) +(def (with_env temp poly) (All (_ a) (-> Env (Parser a) (Parser a))) (.function (_ [env inputs]) (case (//.result poly [temp inputs]) @@ -106,7 +106,7 @@ {try.#Success [[_ remaining] output]} {try.#Success [[env remaining] output]}))) -(def: .public next +(def .public next (Parser Type) (.function (_ [env inputs]) (case inputs @@ -116,7 +116,7 @@ {.#Item headT tail} {try.#Success [[env inputs] headT]}))) -(def: .public any +(def .public any (Parser Type) (.function (_ [env inputs]) (case inputs @@ -126,7 +126,7 @@ {.#Item headT tail} {try.#Success [[env tail] headT]}))) -(def: .public (local types poly) +(def .public (local types poly) (All (_ a) (-> (List Type) (Parser a) (Parser a))) (.function (_ [env pass_through]) (case (result' env poly types) @@ -136,11 +136,11 @@ {try.#Success output} {try.#Success [[env pass_through] output]}))) -(def: (label idx) +(def (label idx) (-> Nat Code) (code.local (all text#composite "label" text.tab (n#encoded idx)))) -(def: .public (with_extension type poly) +(def .public (with_extension type poly) (All (_ a) (-> Type (Parser a) (Parser [Code a]))) (.function (_ [env inputs]) (let [current_id (dictionary.size env) @@ -155,7 +155,7 @@ {try.#Success [[env inputs'] [g!var output]]})))) (with_template [<name> <flattener> <exception>] - [(`` (def: .public (<name> poly) + [(`` (def .public (<name> poly) (All (_ a) (-> (Parser a) (Parser a))) (do //.monad [headT ..any] @@ -168,7 +168,7 @@ [tuple type.flat_tuple ..not_tuple] ) -(def: polymorphic' +(def polymorphic' (Parser [Nat Type]) (do //.monad [headT any @@ -177,7 +177,7 @@ (//.failure (exception.error ..not_polymorphic headT)) (in [num_arg bodyT])))) -(def: .public (polymorphic poly) +(def .public (polymorphic poly) (All (_ a) (-> (Parser a) (Parser [Code (List Code) a]))) (do [! //.monad] [headT any @@ -214,7 +214,7 @@ [output poly] (in [funcL all_varsL output]))))) -(def: .public (function in_poly out_poly) +(def .public (function in_poly out_poly) (All (_ i o) (-> (Parser i) (Parser o) (Parser [i o]))) (do //.monad [headT any @@ -224,7 +224,7 @@ (local (list outputT) out_poly)) (//.failure (exception.error ..not_function headT))))) -(def: .public (applied poly) +(def .public (applied poly) (All (_ a) (-> (Parser a) (Parser a))) (do //.monad [headT any @@ -234,7 +234,7 @@ (..local {.#Item funcT paramsT} poly)))) (with_template [<name> <test>] - [(def: .public (<name> expected) + [(def .public (<name> expected) (-> Type (Parser Any)) (do //.monad [actual any] @@ -247,14 +247,14 @@ [super (function.flipped check.subsumes?)] ) -(def: .public (argument env idx) +(def .public (argument env idx) (-> Env Nat Nat) (let [env_level (n./ 2 (dictionary.size env)) parameter_level (n./ 2 idx) parameter_idx (n.% 2 idx)] (|> env_level -- (n.- parameter_level) (n.* 2) (n.+ parameter_idx)))) -(def: .public parameter +(def .public parameter (Parser Code) (do //.monad [env ..env @@ -271,7 +271,7 @@ _ (//.failure (exception.error ..not_parameter headT))))) -(def: .public (this_parameter id) +(def .public (this_parameter id) (-> Nat (Parser Any)) (do //.monad [env ..env @@ -285,7 +285,7 @@ _ (//.failure (exception.error ..not_parameter headT))))) -(def: .public existential +(def .public existential (Parser Nat) (do //.monad [headT any] @@ -296,7 +296,7 @@ _ (//.failure (exception.error ..not_existential headT))))) -(def: .public named +(def .public named (Parser [Symbol Type]) (do //.monad [inputT any] @@ -307,7 +307,7 @@ _ (//.failure (exception.error ..not_named inputT))))) -(def: .public (recursive poly) +(def .public (recursive poly) (All (_ a) (-> (Parser a) (Parser [Code a]))) (do [! //.monad] [headT any] @@ -323,7 +323,7 @@ _ (//.failure (exception.error ..not_recursive headT))))) -(def: .public recursive_self +(def .public recursive_self (Parser Code) (do //.monad [env ..env @@ -337,7 +337,7 @@ _ (//.failure (exception.error ..not_recursive headT))))) -(def: .public recursive_call +(def .public recursive_call (Parser Code) (do [! //.monad] [env ..env diff --git a/stdlib/source/library/lux/control/parser/xml.lux b/stdlib/source/library/lux/control/parser/xml.lux index 05680953a..16802de51 100644 --- a/stdlib/source/library/lux/control/parser/xml.lux +++ b/stdlib/source/library/lux/control/parser/xml.lux @@ -40,7 +40,7 @@ (exception.report "Inputs" (exception.listing (at /.codec encoded) inputs))) -(def: (result' parser attrs documents) +(def (result' parser attrs documents) (All (_ a) (-> (Parser a) Attrs (List XML) (Try a))) (case (//.result parser [attrs documents]) {try.#Success [[attrs' remaining] output]} @@ -51,11 +51,11 @@ {try.#Failure error} {try.#Failure error})) -(def: .public (result parser documents) +(def .public (result parser documents) (All (_ a) (-> (Parser a) (List XML) (Try a))) (..result' parser /.attributes documents)) -(def: .public text +(def .public text (Parser Text) (function (_ [attrs documents]) (case documents @@ -70,7 +70,7 @@ {/.#Node _} (exception.except ..unexpected_input []))))) -(def: .public tag +(def .public tag (Parser Tag) (function (_ [attrs documents]) (case documents @@ -85,7 +85,7 @@ {/.#Node tag _ _} {try.#Success [[attrs documents] tag]})))) -(def: .public (attribute name) +(def .public (attribute name) (-> Attribute (Parser Text)) (function (_ [attrs documents]) (case (dictionary.value name attrs) @@ -95,7 +95,7 @@ {.#Some value} {try.#Success [[attrs documents] value]}))) -(def: .public (node expected parser) +(def .public (node expected parser) (All (_ a) (-> Tag (Parser a) (Parser a))) (function (_ [attrs documents]) (case documents @@ -114,7 +114,7 @@ (try#each (|>> [[attrs tail]]))) (exception.except ..wrong_tag [expected actual])))))) -(def: .public any +(def .public any (Parser XML) (function (_ [attrs documents]) (case documents @@ -126,7 +126,7 @@ (exception: .public nowhere) -(def: .public (somewhere parser) +(def .public (somewhere parser) (All (_ a) (-> (Parser a) (Parser a))) (function (again [attrs input]) (case (//.result parser [attrs input]) diff --git a/stdlib/source/library/lux/control/pipe.lux b/stdlib/source/library/lux/control/pipe.lux index 611aaf179..7f7762924 100644 --- a/stdlib/source/library/lux/control/pipe.lux +++ b/stdlib/source/library/lux/control/pipe.lux @@ -19,29 +19,29 @@ ["n" nat] ["i" int]]]]]) -(def: body +(def body (Parser (List Code)) (<code>.tuple (<>.some <code>.any))) -(def: .public new +(def .public new (syntax (_ [start <code>.any body ..body prev <code>.any]) (in (list (` (|> (~ start) (~+ body))))))) -(def: .public let +(def .public let (syntax (_ [binding <code>.any body <code>.any prev <code>.any]) (in (list (` (.let [(~ binding) (~ prev)] (~ body))))))) -(def: _reversed_ +(def _reversed_ (Parser Any) (function (_ tokens) {try.#Success [(list.reversed tokens) []]})) -(def: .public cond +(def .public cond (syntax (_ [_ _reversed_ prev <code>.any else ..body @@ -55,7 +55,7 @@ (` (|> (~ g!temp) (~+ then)))))) (|> (~ g!temp) (~+ else)))))))))) -(def: .public if +(def .public if (syntax (_ [test ..body then ..body else ..body @@ -64,7 +64,7 @@ [(~+ else)] (~ prev))))))) -(def: .public when +(def .public when (syntax (_ [test ..body then ..body prev <code>.any]) @@ -72,7 +72,7 @@ [] (~ prev))))))) -(def: .public while +(def .public while (syntax (_ [test ..body then ..body prev <code>.any]) @@ -82,7 +82,7 @@ ((~ g!again) (|> (~ g!temp) (~+ then))) (~ g!temp))))))))) -(def: .public do +(def .public do (syntax (_ [monad <code>.any steps (<>.some ..body) prev <code>.any]) @@ -100,7 +100,7 @@ _ (in (list prev)))))) -(def: .public exec +(def .public exec (syntax (_ [body ..body prev <code>.any]) (with_symbols [g!temp] @@ -108,7 +108,7 @@ (.exec (|> (~ g!temp) (~+ body)) (~ g!temp))))))))) -(def: .public tuple +(def .public tuple (syntax (_ [paths (<>.many ..body) prev <code>.any]) (with_symbols [g!temp] @@ -116,7 +116,7 @@ [(~+ (list#each (function (_ body) (` (|> (~ g!temp) (~+ body)))) paths))]))))))) -(def: .public case +(def .public case (syntax (_ [branches (<>.many (<>.and <code>.any <code>.any)) prev <code>.any]) (in (list (` (.case (~ prev) diff --git a/stdlib/source/library/lux/control/reader.lux b/stdlib/source/library/lux/control/reader.lux index dc9c65f57..923b10562 100644 --- a/stdlib/source/library/lux/control/reader.lux +++ b/stdlib/source/library/lux/control/reader.lux @@ -10,62 +10,62 @@ (type: .public (Reader r a) (-> r a)) -(def: .public read +(def .public read (All (_ r) (Reader r r)) (function (_ env) env)) -(def: .public (local change proc) +(def .public (local change proc) (All (_ r a) (-> (-> r r) (Reader r a) (Reader r a))) (|>> change proc)) -(def: .public (result env proc) +(def .public (result env proc) (All (_ r a) (-> r (Reader r a) a)) (proc env)) -(def: .public functor +(def .public functor (All (_ r) (Functor (Reader r))) (implementation - (def: (each f fa) + (def (each f fa) (function (_ env) (f (fa env)))))) -(def: .public apply +(def .public apply (All (_ r) (Apply (Reader r))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (function (_ env) ((ff env) (fa env)))))) -(def: .public monad +(def .public monad (All (_ r) (Monad (Reader r))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (in x) + (def (in x) (function (_ env) x)) - (def: (conjoint mma) + (def (conjoint mma) (function (_ env) (mma env env))))) -(def: .public (with monad) +(def .public (with monad) (All (_ !) (-> (Monad !) (All (_ e) (Monad (All (_ a) (Reader e (! a))))))) (implementation - (def: functor + (def functor (functor.composite ..functor (the monad.functor monad))) - (def: in + (def in (|>> (at monad in) (at ..monad in))) - (def: (conjoint eMeMa) + (def (conjoint eMeMa) (function (_ env) (do monad [eMa (result env eMeMa)] (result env eMa)))))) -(def: .public lifted +(def .public lifted (All (_ ! e a) (-> (! a) (Reader e (! a)))) (at ..monad in)) diff --git a/stdlib/source/library/lux/control/region.lux b/stdlib/source/library/lux/control/region.lux index ea1abcec3..2c91dbbb8 100644 --- a/stdlib/source/library/lux/control/region.lux +++ b/stdlib/source/library/lux/control/region.lux @@ -23,7 +23,7 @@ (! [(List (Cleaner r !)) (Try a)]))) -(def: separator +(def separator Text (format text.new_line "-----------------------------------------" text.new_line @@ -42,7 +42,7 @@ (format separator error|output)))) -(def: (clean clean_up output) +(def (clean clean_up output) (All (_ a) (-> (Try Any) (Try a) (Try a))) (case clean_up {try.#Success _} @@ -51,7 +51,7 @@ {try.#Failure error} (exception.except ..clean_up_error [error output]))) -(def: .public (run! monad computation) +(def .public (run! monad computation) (All (_ ! a) (-> (Monad !) (All (_ r) (Region r ! a)) (! (Try a)))) @@ -61,7 +61,7 @@ (monad.each ! (function (_ cleaner) (cleaner []))) (at ! each (list#mix clean output))))) -(def: .public (acquire! monad cleaner value) +(def .public (acquire! monad cleaner value) (All (_ ! a) (-> (Monad !) (-> a (! (Try Any))) a (All (_ r) (Region r ! a)))) (function (_ [region cleaners]) @@ -69,12 +69,12 @@ cleaners} {try.#Success value}]))) -(def: .public (functor super) +(def .public (functor super) (All (_ !) (-> (Functor !) (All (_ r) (Functor (Region r !))))) (implementation - (def: (each f) + (def (each f) (function (_ fa) (function (_ region+cleaners) (at super each @@ -87,15 +87,15 @@ {try.#Failure error})]) (fa region+cleaners))))))) -(def: .public (apply super) +(def .public (apply super) (All (_ !) (-> (Monad !) (All (_ r) (Apply (Region r !))))) (implementation - (def: functor + (def functor (..functor (the monad.functor super))) - (def: (on fa ff) + (def (on fa ff) (function (_ [region cleaners]) (do super [[cleaners ef] (ff [region cleaners]) @@ -112,19 +112,19 @@ {try.#Failure error} (in [cleaners {try.#Failure error}]))))))) -(def: .public (monad super) +(def .public (monad super) (All (_ !) (-> (Monad !) (All (_ r) (Monad (Region r !))))) (implementation - (def: functor + (def functor (..functor (the monad.functor super))) - (def: (in value) + (def (in value) (function (_ [region cleaners]) (at super in [cleaners {try.#Success value}]))) - (def: (conjoint ffa) + (def (conjoint ffa) (function (_ [region cleaners]) (do super [[cleaners efa] (ffa [region cleaners])] @@ -135,20 +135,20 @@ {try.#Failure error} (in [cleaners {try.#Failure error}]))))))) -(def: .public (failure monad error) +(def .public (failure monad error) (All (_ ! a) (-> (Monad !) Text (All (_ r) (Region r ! a)))) (function (_ [region cleaners]) (at monad in [cleaners {try.#Failure error}]))) -(def: .public (except monad exception message) +(def .public (except monad exception message) (All (_ ! e a) (-> (Monad !) (Exception e) e (All (_ r) (Region r ! a)))) (failure monad (exception.error exception message))) -(def: .public (lifted monad operation) +(def .public (lifted monad operation) (All (_ ! a) (-> (Monad !) (! a) (All (_ r) (Region r ! a)))) diff --git a/stdlib/source/library/lux/control/remember.lux b/stdlib/source/library/lux/control/remember.lux index 8cd386ca6..1110c57bf 100644 --- a/stdlib/source/library/lux/control/remember.lux +++ b/stdlib/source/library/lux/control/remember.lux @@ -36,7 +36,7 @@ {.#None} ""))) -(def: deadline +(def deadline (Parser Date) (all <>.either (<>#each (|>> instant.of_millis instant.date) @@ -50,7 +50,7 @@ {try.#Failure message} (<>.failure message))))) -(def: .public remember +(def .public remember (syntax (_ [deadline ..deadline message <c>.text focus (<>.maybe <c>.any)]) @@ -66,7 +66,7 @@ (meta.failure (exception.error ..must_remember [deadline today message focus])))))) (with_template [<name> <message>] - [(`` (def: .public <name> + [(`` (def .public <name> (syntax (_ [deadline ..deadline message <c>.text focus (<>.maybe <c>.any)]) diff --git a/stdlib/source/library/lux/control/security/capability.lux b/stdlib/source/library/lux/control/security/capability.lux index 482f61161..6df5eaf19 100644 --- a/stdlib/source/library/lux/control/security/capability.lux +++ b/stdlib/source/library/lux/control/security/capability.lux @@ -26,20 +26,20 @@ (primitive .public (Capability brand input output) (-> input output) - (def: capability + (def capability (All (_ brand input output) (-> (-> input output) (Capability brand input output))) (|>> abstraction)) - (def: .public (use capability input) + (def .public (use capability input) (All (_ brand input output) (-> (Capability brand input output) input output)) ((representation capability) input)) - (def: .public capability: + (def .public capability: (syntax (_ [[export_policy declaration [forger input output]] (|export|.parser (all <>.and @@ -55,14 +55,14 @@ (in (list (` (type: (~ export_policy) (~ (|declaration|.format declaration)) (~ capability))) - (` (def: (~ (code.local forger)) + (` (def (~ (code.local forger)) (All ((~ g!_) (~+ (list#each code.local vars))) (-> (-> (~ input) (~ output)) (~ capability))) (~! ..capability))) )))))) - (def: .public (async capability) + (def .public (async capability) (All (_ brand input output) (-> (Capability brand input (IO output)) (Capability brand input (Async output)))) diff --git a/stdlib/source/library/lux/control/security/policy.lux b/stdlib/source/library/lux/control/security/policy.lux index f8856c593..fe683cf05 100644 --- a/stdlib/source/library/lux/control/security/policy.lux +++ b/stdlib/source/library/lux/control/security/policy.lux @@ -27,7 +27,7 @@ (-> (Policy brand value from) (Policy brand value to)))) - (def: .public (delegation downgrade upgrade) + (def .public (delegation downgrade upgrade) (All (_ brand from to) (-> (Can_Downgrade brand from) (Can_Upgrade brand to) (Delegation brand from to))) @@ -37,43 +37,43 @@ (-> (Privilege brand label) (scope label))) - (def: privilege + (def privilege Privilege [#can_upgrade (|>> abstraction) #can_downgrade (|>> representation)]) - (def: .public (with_policy context) + (def .public (with_policy context) (All (_ brand scope) (Ex (_ label) (-> (Context brand scope label) (scope label)))) (context ..privilege)) - (def: (of_policy constructor) + (def (of_policy constructor) (-> Type Type) (type (All (_ brand label) (constructor (All (_ value) (Policy brand value label)))))) - (def: .public functor + (def .public functor (~ (..of_policy Functor)) (implementation - (def: (each f fa) + (def (each f fa) (|> fa representation f abstraction)))) - (def: .public apply + (def .public apply (~ (..of_policy Apply)) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (abstraction ((representation ff) (representation fa)))))) - (def: .public monad + (def .public monad (~ (..of_policy Monad)) (implementation - (def: functor ..functor) - (def: in (|>> abstraction)) - (def: conjoint (|>> representation)))) + (def functor ..functor) + (def in (|>> abstraction)) + (def conjoint (|>> representation)))) ) (with_template [<brand> <value> <upgrade> <downgrade>] diff --git a/stdlib/source/library/lux/control/state.lux b/stdlib/source/library/lux/control/state.lux index dc007f65a..484592e71 100644 --- a/stdlib/source/library/lux/control/state.lux +++ b/stdlib/source/library/lux/control/state.lux @@ -9,70 +9,70 @@ (type: .public (State s a) (-> s [s a])) -(def: .public get +(def .public get (All (_ s) (State s s)) (function (_ state) [state state])) -(def: .public (put new_state) +(def .public (put new_state) (All (_ s) (-> s (State s Any))) (function (_ state) [new_state []])) -(def: .public (update change) +(def .public (update change) (All (_ s) (-> (-> s s) (State s Any))) (function (_ state) [(change state) []])) -(def: .public (use user) +(def .public (use user) (All (_ s a) (-> (-> s a) (State s a))) (function (_ state) [state (user state)])) -(def: .public (local change action) +(def .public (local change action) (All (_ s a) (-> (-> s s) (State s a) (State s a))) (function (_ state) (let [[state' output] (action (change state))] [state output]))) -(def: .public (result state action) +(def .public (result state action) (All (_ s a) (-> s (State s a) [s a])) (action state)) -(def: .public functor +(def .public functor (All (_ s) (Functor (State s))) (implementation - (def: (each f ma) + (def (each f ma) (function (_ state) (let [[state' a] (ma state)] [state' (f a)]))))) -(def: .public apply +(def .public apply (All (_ s) (Apply (State s))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (function (_ state) (let [[state' f] (ff state) [state'' a] (fa state')] [state'' (f a)]))))) -(def: .public monad +(def .public monad (All (_ s) (Monad (State s))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (in a) + (def (in a) (function (_ state) [state a])) - (def: (conjoint mma) + (def (conjoint mma) (function (_ state) (let [[state' ma] (mma state)] (ma state')))))) -(def: .public (while condition body) +(def .public (while condition body) (All (_ s) (-> (State s Bit) (State s Any) (State s Any))) (do [! ..monad] [execute? condition] @@ -82,26 +82,26 @@ (while condition body)) (in [])))) -(def: .public (do_while condition body) +(def .public (do_while condition body) (All (_ s) (-> (State s Bit) (State s Any) (State s Any))) (do ..monad [_ body] (while condition body))) -(def: (with//functor functor) +(def (with//functor functor) (All (_ M s) (-> (Functor M) (Functor (All (_ a) (-> s (M [s a])))))) (implementation - (def: (each f sfa) + (def (each f sfa) (function (_ state) (at functor each (function (_ [s a]) [s (f a)]) (sfa state)))))) -(def: (with//apply monad) +(def (with//apply monad) (All (_ M s) (-> (Monad M) (Apply (All (_ a) (-> s (M [s a])))))) (implementation - (def: functor (with//functor (at monad functor))) + (def functor (with//functor (at monad functor))) - (def: (on sFa sFf) + (def (on sFa sFf) (function (_ state) (do monad [[state f] (sFf state) @@ -111,26 +111,26 @@ (type: .public (+State M s a) (-> s (M [s a]))) -(def: .public (result' state action) +(def .public (result' state action) (All (_ M s a) (-> s (+State M s a) (M [s a]))) (action state)) -(def: .public (with monad) +(def .public (with monad) (All (_ M s) (-> (Monad M) (Monad (+State M s)))) (implementation - (def: functor (with//functor (at monad functor))) + (def functor (with//functor (at monad functor))) - (def: (in a) + (def (in a) (function (_ state) (at monad in [state a]))) - (def: (conjoint sMsMa) + (def (conjoint sMsMa) (function (_ state) (do monad [[state' sMa] (sMsMa state)] (sMa state')))))) -(def: .public (lifted monad ma) +(def .public (lifted monad ma) (All (_ M s a) (-> (Monad M) (M a) (+State M s a))) (function (_ state) (do monad diff --git a/stdlib/source/library/lux/control/thread.lux b/stdlib/source/library/lux/control/thread.lux index bb48b31b0..4dbe81f34 100644 --- a/stdlib/source/library/lux/control/thread.lux +++ b/stdlib/source/library/lux/control/thread.lux @@ -28,14 +28,14 @@ (type: .public (Box t a) (Box'' t (Mutable a a))) - (def: .public (box init) + (def .public (box init) (All (_ a) (-> a (All (_ !) (Thread ! (Box ! a))))) (function (_ !) (|> (array.empty 1) (array.has! 0 (variance.write init)) abstraction))) - (def: .public (read! box) + (def .public (read! box) (All (_ ! r w) (-> (Box' ! r w) (Thread ! r))) (function (_ !) (|> box @@ -43,7 +43,7 @@ (array.item 0) variance.read))) - (def: .public (write! value box) + (def .public (write! value box) (All (_ r w) (-> w (All (_ !) (-> (Box' ! r w) (Thread ! Any))))) (function (_ !) (|> box @@ -52,49 +52,49 @@ abstraction))) ) -(def: .public (result thread) +(def .public (result thread) (All (_ a) (-> (All (_ !) (Thread ! a)) a)) (thread [])) -(def: .public io +(def .public io (All (_ a) (-> (All (_ !) (Thread ! a)) (IO a))) (|>> ..result io.io)) -(def: .public functor +(def .public functor (All (_ !) (Functor (Thread !))) (implementation - (def: (each f) + (def (each f) (function (_ fa) (function (_ !) (f (fa !))))))) -(def: .public apply +(def .public apply (All (_ !) (Apply (Thread !))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (function (_ !) ((ff !) (fa !)))))) -(def: .public monad +(def .public monad (All (_ !) (Monad (Thread !))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (in value) + (def (in value) (function (_ !) value)) - (def: (conjoint ffa) + (def (conjoint ffa) (function (_ !) ((ffa !) !))))) -(def: .public (update! f box) +(def .public (update! f box) (All (_ ! r w) (-> (-> r w) (Box' ! r w) (Thread ! [r w]))) (do ..monad [old (read! box) diff --git a/stdlib/source/library/lux/control/try.lux b/stdlib/source/library/lux/control/try.lux index 6d0467043..23d3cf178 100644 --- a/stdlib/source/library/lux/control/try.lux +++ b/stdlib/source/library/lux/control/try.lux @@ -15,10 +15,10 @@ {#Failure Text} {#Success a})) -(def: .public functor +(def .public functor (Functor Try) (implementation - (def: (each f ma) + (def (each f ma) (case ma {#Success datum} {#Success (f datum)} @@ -27,12 +27,12 @@ it (as_expected it))))) -(def: .public apply +(def .public apply (Apply Try) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (case ff {#Success f} (case fa @@ -47,15 +47,15 @@ it (as_expected it))))) -(def: .public monad +(def .public monad (Monad Try) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (in a) + (def (in a) {#Success a}) - (def: (conjoint mma) + (def (conjoint mma) (case mma {#Success ma} ma @@ -64,19 +64,19 @@ it (as_expected it))))) -(def: .public (with monad) +(def .public (with monad) ... TODO: Replace (All (_ a) (! (Try a))) with (functor.Then ! Try) (All (_ !) (-> (Monad !) (Monad (All (_ a) (! (Try a)))))) (implementation - (def: functor + (def functor (functor.composite (the monad.functor monad) ..functor)) - (def: in + (def in (|>> (at ..monad in) (at monad in))) - (def: (conjoint MeMea) + (def (conjoint MeMea) (do monad [eMea MeMea] (case eMea @@ -87,14 +87,14 @@ it (in (as_expected it))))))) -(def: .public (lifted monad) +(def .public (lifted monad) (All (_ ! a) (-> (Monad !) (-> (! a) (! (Try a))))) (at monad each (at ..monad in))) -(def: .public (equivalence (open "_#[0]")) +(def .public (equivalence (open "_#[0]")) (All (_ a) (-> (Equivalence a) (Equivalence (Try a)))) (implementation - (def: (= reference sample) + (def (= reference sample) (case [reference sample] [{#Success reference} {#Success sample}] (_#= reference sample) @@ -106,7 +106,7 @@ false )))) -(def: .public (trusted try) +(def .public (trusted try) (All (_ a) (-> (Try a) a)) (case try @@ -116,7 +116,7 @@ {#Failure message} (panic! message))) -(def: .public (maybe try) +(def .public (maybe try) (All (_ a) (-> (Try a) (Maybe a))) (case try @@ -127,7 +127,7 @@ _ {.#None})) -(def: .public (of_maybe maybe) +(def .public (of_maybe maybe) (All (_ a) (-> (Maybe a) (Try a))) (case maybe @@ -138,7 +138,7 @@ {#Failure (`` (("lux in-module" (~~ (static .prelude)) .symbol#encoded) (symbol ..of_maybe)))})) -(def: .public else +(def .public else (macro (_ tokens compiler) (case tokens (pattern (list else try)) @@ -153,7 +153,7 @@ _ {#Failure "Wrong syntax for 'else'"}))) -(def: .public when +(def .public when (macro (_ tokens state) (case tokens (pattern (.list test then)) diff --git a/stdlib/source/library/lux/control/writer.lux b/stdlib/source/library/lux/control/writer.lux index 88b536e30..6df2cf695 100644 --- a/stdlib/source/library/lux/control/writer.lux +++ b/stdlib/source/library/lux/control/writer.lux @@ -13,54 +13,54 @@ [#log log #value value])) -(def: .public (write message) +(def .public (write message) (All (_ log) (-> log (Writer log Any))) [message []]) -(def: .public functor +(def .public functor (All (_ l) (Functor (Writer l))) (implementation - (def: (each f fa) + (def (each f fa) (let [[log datum] fa] [log (f datum)])))) -(def: .public (apply monoid) +(def .public (apply monoid) (All (_ l) (-> (Monoid l) (Apply (Writer l)))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: (on fa ff) + (def (on fa ff) (let [[log1 f] ff [log2 a] fa] [(at monoid composite log1 log2) (f a)])))) -(def: .public (monad monoid) +(def .public (monad monoid) (All (_ l) (-> (Monoid l) (Monad (Writer l)))) (implementation - (def: functor ..functor) + (def functor ..functor) - (def: in + (def in (|>> [(at monoid identity)])) - (def: (conjoint mma) + (def (conjoint mma) (let [[log1 [log2 a]] mma] [(at monoid composite log1 log2) a])))) -(def: .public (with monoid monad) +(def .public (with monoid monad) (All (_ l M) (-> (Monoid l) (Monad M) (Monad (All (_ a) (M (Writer l a)))))) (implementation - (def: functor + (def functor (functor.composite (the monad.functor monad) ..functor)) - (def: in + (def in (let [writer (..monad monoid)] (|>> (at writer in) (at monad in)))) - (def: (conjoint MlMla) + (def (conjoint MlMla) (do monad [[l1 Mla] (for @.old (is {.#Apply (Writer (parameter 0) @@ -74,7 +74,7 @@ [l2 a] Mla] (in [(at monoid composite l1 l2) a]))))) -(def: .public (lifted monoid monad) +(def .public (lifted monoid monad) (All (_ l M a) (-> (Monoid l) (Monad M) (-> (M a) (M (Writer l a))))) |