*almost* composition in writer monad

Hi, 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. Edsko

Isn't that "sequence" in State monad? On 4 Mar 2009, at 19:37, Edsko de Vries wrote:
Hi,
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.
Edsko
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Doh, yes, of course. I had a feeling I was missing something obvious :) Thanks :) On 4 Mar 2009, at 17:29, Miguel Mitrofanov wrote:
Isn't that "sequence" in State monad?
On 4 Mar 2009, at 19:37, Edsko de Vries wrote:
Hi,
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.
Edsko
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (2)
-
Edsko de Vries
-
Miguel Mitrofanov