From f7047f1c3966bd1727c1a3729295def3c9913ab8 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 29 Jul 2017 11:18:12 -0400 Subject: - Added Functor, Applicative and Monad implementations for Lazy. --- stdlib/source/lux/data/lazy.lux | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'stdlib/source') 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) + + (def: (wrap a) + (freeze a)) + + (def: (apply ff fa) + (freeze ((thaw ff) (thaw fa))))) + +(struct: #export _ (Monad Lazy) + (def: applicative Applicative) + + (def: join thaw)) -- cgit v1.2.3