Monads/Writer monad: Difference between revisions

Content added Content deleted
Line 37: Line 37:


// DERIVE LOGGING VERSIONS OF EACH FUNCTION
// DERIVE LOGGING VERSIONS OF EACH FUNCTION

function loggingVersion(f, strLog) {
function loggingVersion(f, strLog) {
return function (v) {
return function (v) {
Line 68: Line 68:
// to the contents of a wrapped value
// to the contents of a wrapped value
// and return a wrapped result (with extended log)
// and return a wrapped result (with extended log)

// Writer a -> (a -> Writer b) -> Writer b
// Writer a -> (a -> Writer b) -> Writer b
function writerBind(w, f) {
function writerBind(w, f) {
Line 90: Line 90:


var half_of_addOne_of_root = function (v) {
var half_of_addOne_of_root = function (v) {
return logCompose([log_half, log_addOne, log_root],v);
return logCompose([log_half, log_addOne, log_root], v);
};
};