aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source')
-rw-r--r--stdlib/source/lux/data/lazy.lux25
1 files changed, 22 insertions, 3 deletions
diff --git a/stdlib/source/lux/data/lazy.lux b/stdlib/source/lux/data/lazy.lux
index 1f4566eee..d2533644a 100644
--- a/stdlib/source/lux/data/lazy.lux
+++ b/stdlib/source/lux/data/lazy.lux
@@ -1,7 +1,9 @@
(;module:
lux
(lux [io]
- (control monad)
+ (control functor
+ applicative
+ monad)
(concurrency ["A" atom])
[macro]
(macro ["s" syntax #+ syntax:])
@@ -12,8 +14,7 @@
(def: #hidden (freeze' generator)
(All [a] (-> (-> [] a) (Lazy a)))
- (let [cache (: (A;Atom (Maybe ($ +0)))
- (A;atom #;None))]
+ (let [cache (A;atom (: (Maybe ($ +0)) #;None))]
(@model (function [_]
(case (io;run (A;get cache))
(#;Some value)
@@ -32,3 +33,21 @@
(do @
[g!_ (macro;gensym "_")]
(wrap (list (` (freeze' (function [(~ g!_)] (~ expr))))))))
+
+(struct: #export _ (Functor Lazy)
+ (def: (map f fa)
+ (freeze (f (thaw fa)))))
+
+(struct: #export _ (Applicative Lazy)
+ (def: functor Functor<Lazy>)
+
+ (def: (wrap a)
+ (freeze a))
+
+ (def: (apply ff fa)
+ (freeze ((thaw ff) (thaw fa)))))
+
+(struct: #export _ (Monad Lazy)
+ (def: applicative Applicative<Lazy>)
+
+ (def: join thaw))