Module Relude_WriterT.WithMonad

Creates a Writer monad with the given inner monad

Parameters

Signature

type t('a, 'w) =
| WriterT(Monad.t(('a, 'w)))
;
let make: w a. Monad.t(('a, 'w)) => t('a'w);
let runWriterT: w a. t('a'w) => Monad.t(('a, 'w));

Run the writer, and get the result value a, and the log w

let execWriterT: w a. t('a'w) => Monad.t('w);

Run the writer, and discard the result value a, only returning the log w

let mapWriterT: w a b. (Monad.t(('a, 'w)) => Monad.t(('b, 'w))) => t('a'w) => t('b'w);

Maps a inner monad-converting function over the WriterT. Note: this is not exactly the same as purescript/haskell in that we don't allow monad changes here for the sake of simplicity.

let tell: w. 'w => t(unit, 'w);

Writes a single value to the log

let listen: w a. t('a'w) => t(('a, 'w)'w);

Surfaces the current value of the log w along with the current result value a in a tuple.

let pass: w a. t(('a, ('w => 'w))'w) => t('a'w);

Applies a log-modifying function provided in the result tuple to the log

let listens: w1 w2 a. ('w1 => 'w2) => t('a'w1) => t(('a, 'w2)'w1);

Surfaces the current value of the log using a function to transform it.

let censor: w a. ('w => 'w) => t('a'w) => t('a'w);

Modifies the log

let map: w a b. ('a => 'b) => t('a'w) => t('b'w);

Maps a function over the result value a of the WriterT. No change is made to the log.

let applyWithAppendLog: w a b. ('w => 'w => 'w) => t('a => 'b'w) => t('a'w) => t('b'w);

Applies a writer-wrapped function to the result value a of the WriterT. The log values for the Writer-wrapped function and the Writer-wrapped value a are appended in the resulting Writer.

let pureWithEmptyLog: w a. 'w => 'a => t('a'w);

Constructs a Writer with the given value a, and an empty log

let bindWithAppendLog: w a b. ('w => 'w => 'w) => t('a'w) => ('a => t('b'w)) => t('b'w);

Applies an effectful function to the value a, and appends the original log with the new log produced by the effectful function.

module WithLog: (Log: WriterLog.LOG) => { ... };

In order to implement the common typeclasses, we need to know how to append log entries (in most cases). In Haskell/Purescript/Scala/etc. many of the typeclass instances depend on various other specific typeclasses, but here, we are just normalizing on WriterLog, which contains a type for collecting logs, and a Monoid for the type.