diff options
author | Eduardo Julian | 2017-07-29 11:18:12 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-07-29 11:18:12 -0400 |
commit | f7047f1c3966bd1727c1a3729295def3c9913ab8 (patch) | |
tree | f35e59ff3589446d22188b250dcfcd5cc7379c3e /stdlib/source | |
parent | e578df2b0b6d4fd751b8656c16efee54363fc121 (diff) |
- Added Functor, Applicative and Monad implementations for Lazy.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/data/lazy.lux | 25 |
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)) |