## Copyright (c) Eduardo Julian. All rights reserved. ## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. ## If a copy of the MPL was not distributed with this file, ## You can obtain one at http://mozilla.org/MPL/2.0/. (;import lux (lux/control (monoid #as m #refer #all) (functor #as F #refer #all) (monad #as M #refer #all))) ## [Types] (deftype #export (Writer l a) (, l a)) ## [Structures] (defstruct #export Writer/Functor (All [l] (Functor (Writer l))) (def (map f fa) (let [[log datum] fa] [log (f datum)]))) (defstruct #export (Writer/Monad mon) (All [l] (-> (Monoid l) (Monad (Writer l)))) (def _functor Writer/Functor) (def (wrap x) [(:: mon unit) x]) (def (join mma) (let [[log1 [log2 a]] mma] [(:: mon (++ log1 log2)) a])))