Jump to content

Monads/Writer monad: Difference between revisions

m
(Added C++ implementation)
Line 215:
 
// Define a function to create writer monads from the simple functions
auto WriterMakeWriter = [](auto f, string message)
{
return [=](double x){return LoggingMonad(f(x), message);};
Line 221:
 
// Derive writer versions of the simple functions
auto writerRoot = WriterMakeWriter(Root, "Taking square root");
auto writerAddOne = WriterMakeWriter(AddOne, "Adding 1");
auto writerHalf = WriterMakeWriter(Half, "Dividing by 2");
 
 
Line 241:
Result: 1.61803
</pre>
 
 
=={{header|EchoLisp}}==
125

edits

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