Monads/Writer monad: Difference between revisions

Content added Content deleted
Line 664: Line 664:
=={{header|Nim}}==
=={{header|Nim}}==
<lang Nim>from math import sqrt
<lang Nim>from math import sqrt
from sugar import `=>`
from sugar import `=>`, `->`


type
type
Line 670: Line 670:
WriterBind = proc(a: WriterUnit): WriterUnit
WriterBind = proc(a: WriterUnit): WriterUnit


proc bindWith(f: proc(x: float): float; log: string): WriterBind =
proc bindWith(f: (x: float) -> float; log: string): WriterBind =
result = (proc(a: WriterUnit): WriterUnit =
result = (proc(a: WriterUnit): WriterUnit =
(f(a[0]), a[1] & log)
(f(a[0]), a[1] & log)