
16 Jan
2009
16 Jan
'09
10:04 a.m.
On Fri, 2009-01-16 at 14:16 +0100, david48 wrote:
Part of the problem is that something like a monoid is so general that I can't wrap my head around why going so far in the abstraction. For example, the writer monad works with a monoid; using the writer monad with strings makes sense because the mappend operation for lists is (++), now why should I care that I can use the writer monad with numbers which it will sum ?
To accumulate a running count, maybe? A fairly common pattern for counting in imperative languages is int i = 0; while (<get a value>) i+= <count of something in value> Using the writer monad, this turns into execWriter $ mapM_ (write . countFunction) $ getValues jcc