Monads/Writer monad: Difference between revisions
→{{header|F_Sharp|F#}}
(Realize in F#) |
|||
Line 293:
<lang fsharp>
// Monads/Writer monad . Nigel Galloway: July 20th., 2022
type Riter<'n
let eval=function |Riter(n,g)->(n,g)
let compose f=function |Riter(n,g)->let n,l=eval(f n) in Riter(n,List.append g l)
let initV
let sqrt n=
let
let
let result,log=eval((initV
log|>List.iter(printfn "%s")
printfn "Final value = %f" result
Line 309 ⟶ 308:
Initial Value 5.000000
Took square root
Added 1.000000
Divided by 2.000000
Final value =
</pre>
=={{header|Factor}}==
Factor comes with an implementation of Haskell-style monads in the <code>monads</code> vocabulary.
|