[Haskell-cafe] *almost* composition in writer monad

Edsko de Vries devriese at cs.tcd.ie
Wed Mar 4 11:37:31 EST 2009


Does this function remind anybody of anything? It seems like I'm  
missing an obvious abstraction:

composeWriter :: [a -> (a, b)] -> a -> (a, [b])
composeWriter [] a
   = (a, [])
composeWriter (f:fs) a
   = let (a', b) = f a
            (final_a, bs) = composeWriter fs a'
      in (final_a, b:bs)

It's almost but not quite composition for functions in the Writer  
monad; the difference is that every function has exactly one b result,  
rather than a list of them.


More information about the Haskell-Cafe mailing list