Monads/Writer monad: Difference between revisions

(Added Go)
Line 421:
divided by 2 -> 1.618033988749895"
}</pre>
 
=={{header|Julia}}==
<lang julia>struct Writer x::Real; msg::String; end
 
Base.show(io::IO, w::Writer) = print(io, w.msg, ": ", w.x)
 
unit(x, logmsg) = Writer(x, logmsg)
 
bind(f, fmsg, w) = unit(f(w.x), fmsg)
 
f1(x) = 7x
f2(x) = x + 8
 
a = unit(3, "after intialization")
b = bind(f1, " after times 7 ", a)
c = bind(f2, " after plus 8", b)
 
println("$a => $b => $c")
</lang>{{out}}
<pre>
after intialization: 3 => after times 7 : 21 => after plus 8: 29
</pre>
 
 
=={{header|Kotlin}}==
4,102

edits