Jump to content

Monads/Writer monad: Difference between revisions

m
Line 429:
unit(x, logmsg) = Writer(x, logmsg)
 
bind(f, fmsg, w) = unit(f(w.x), w.msg * ", " * fmsg)
 
f1(x) = 7x
Line 435:
 
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 intialization, after times 7 : 21 => after intialization, after times 7, after plus 8: 29
</pre>
 
 
=={{header|Kotlin}}==
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.