diff options
author | Eduardo Julian | 2017-04-09 19:41:15 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-04-09 19:41:15 -0400 |
commit | d4c23b4cce91ae8cfcf1bda6b577ff50c55abe3c (patch) | |
tree | 077028003e74b1eda56348b886be13f063fad36b /stdlib/source | |
parent | 2b551329f9f622bfa3e2c0cbf4d223bcfa8496f7 (diff) |
- Added delimited continuations, with static shifting.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/function/cont.lux | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/stdlib/source/lux/function/cont.lux b/stdlib/source/lux/function/cont.lux index 9074f59f0..911e66995 100644 --- a/stdlib/source/lux/function/cont.lux +++ b/stdlib/source/lux/function/cont.lux @@ -22,16 +22,6 @@ (All [a] (-> (Cont a a) a)) (cont id)) -(def: #export (call/cc f) - {#;doc "Call with current continuation."} - (All [a b z] - (-> (-> (-> a (Cont b z)) - (Cont a z)) - (Cont a z))) - (lambda [k] - (f (lambda [a] (lambda [_] (k a))) - k))) - (struct: #export Functor<Cont> (All [o] (Functor (All [i] (Cont i o)))) (def: (map f fv) (lambda [k] (fv (. k f))))) @@ -55,6 +45,16 @@ (lambda [k] (ffa (continue k))))) +(def: #export (call/cc f) + {#;doc "Call with current continuation."} + (All [a b z] + (-> (-> (-> a (Cont b z)) + (Cont a z)) + (Cont a z))) + (lambda [k] + (f (lambda [a] (lambda [_] (k a))) + k))) + (syntax: #export (pending expr) {#;doc (doc "Turns any expression into a function that is pending a continuation." (pending (some-computation some-input)))} @@ -73,3 +73,17 @@ (k [nexus val]))] _ (k [nexus init])] (wrap (undefined)))))) + +(def: #export (reset scope) + (All [i o] (-> (Cont i i) (Cont i o))) + (lambda [k] + (k (run scope)))) + +(def: #export (static f) + (All [a] + (-> (-> (-> a (Cont a a)) + (Cont a a)) + (Cont a a))) + (lambda [oc] + (f (lambda [a] (lambda [ic] (ic (oc a)))) + id))) |