haskell - What is complexity of Control.Monad.Writer for w ~ [a]? -
assuming tell = flip mappend
should quadratic, make writer
instance pretty useless. if it's so, can done improve performance?
i'm thinking of trick used in control.monad.free.church
control.monad.codensity
: should possible reassociate mappend
calls, codensity
reassociates >>=
, haven't figured how exactly.
to sum up:
yes,
tell
ing[a]
has quadratic complexity inwriter
. can avoided usingdlist
(which usescodensity
-like trick talking about) or datatypemappend
isn'to(n^2)
.on top of that,
writer
generates thunks each>>=
used build computation. problem because unlike first case can't worked around. solution usestate
monad instead.
Comments
Post a Comment