
So, I'm doing something like this foldl (>>=) someA list :: Monad m => m a where list :: Monad m => [a -> m a], someA :: Monad m => m a Is there a more concise way to write this? I don't think foldM is what I want -- or is it? -- frigidcode.com

You could do: runKleisli . mconcat . map Kleisli :: Monoid (Kleisli m a b) => [a -> m b] -> a -> m b Would that work for you? On Tue, Apr 16, 2013 at 8:35 PM, Christopher Howard < christopher.howard@frigidcode.com> wrote:
So, I'm doing something like this
foldl (>>=) someA list :: Monad m => m a
where list :: Monad m => [a -> m a], someA :: Monad m => m a
Is there a more concise way to write this? I don't think foldM is what I want -- or is it?
-- frigidcode.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

You could do:
runKleisli . mconcat . map Kleisli :: Monoid (Kleisli m a b) => [a -> m b] -> a -> m b
Would that work for you? I can't find an instance for Monoid (Kleisli m a b) in `base`, so
On 04/16/2013 01:47 PM, Lyndon Maydwell wrote: presumably the author would also have to write this instance? If so - would that really be any different to using that fold? - Ollie

On Tue, Apr 16, 2013 at 01:53:19PM +0100, Oliver Charles wrote:
You could do:
runKleisli . mconcat . map Kleisli :: Monoid (Kleisli m a b) => [a -> m b] -> a -> m b
Would that work for you? I can't find an instance for Monoid (Kleisli m a b) in `base`, so
On 04/16/2013 01:47 PM, Lyndon Maydwell wrote: presumably the author would also have to write this instance? If so - would that really be any different to using that fold?
It doesn't make sense anyway. It would have to be "Kleisli m a a" which would presumably require a newtype. Tom

Yep. I was backstabbed by ghci seemingly having no issue with my definition when I asked for the type. On Tue, Apr 16, 2013 at 9:49 PM, Tom Ellis < tom-lists-haskell-cafe-2013@jaguarpaw.co.uk> wrote:
On Tue, Apr 16, 2013 at 01:53:19PM +0100, Oliver Charles wrote:
You could do:
runKleisli . mconcat . map Kleisli :: Monoid (Kleisli m a b) => [a -> m b] -> a -> m b
Would that work for you? I can't find an instance for Monoid (Kleisli m a b) in `base`, so
On 04/16/2013 01:47 PM, Lyndon Maydwell wrote: presumably the author would also have to write this instance? If so - would that really be any different to using that fold?
It doesn't make sense anyway. It would have to be "Kleisli m a a" which would presumably require a newtype.
Tom
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Right. See also this discussion:
http://www.haskell.org/pipermail/libraries/2009-July/012106.html
Roman
* Tom Ellis
On Tue, Apr 16, 2013 at 01:53:19PM +0100, Oliver Charles wrote:
You could do:
runKleisli . mconcat . map Kleisli :: Monoid (Kleisli m a b) => [a -> m b] -> a -> m b
Would that work for you? I can't find an instance for Monoid (Kleisli m a b) in `base`, so
On 04/16/2013 01:47 PM, Lyndon Maydwell wrote: presumably the author would also have to write this instance? If so - would that really be any different to using that fold?
It doesn't make sense anyway. It would have to be "Kleisli m a a" which would presumably require a newtype.
Tom
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Wow looks like this Monoid instance isn't included in Control.Monad... My
mistake.
On Tue, Apr 16, 2013 at 8:47 PM, Lyndon Maydwell
You could do:
runKleisli . mconcat . map Kleisli :: Monoid (Kleisli m a b) => [a -> m b] -> a -> m b
Would that work for you?
On Tue, Apr 16, 2013 at 8:35 PM, Christopher Howard < christopher.howard@frigidcode.com> wrote:
So, I'm doing something like this
foldl (>>=) someA list :: Monad m => m a
where list :: Monad m => [a -> m a], someA :: Monad m => m a
Is there a more concise way to write this? I don't think foldM is what I want -- or is it?
-- frigidcode.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

* Christopher Howard
So, I'm doing something like this
foldl (>>=) someA list :: Monad m => m a
where list :: Monad m => [a -> m a], someA :: Monad m => m a
Is there a more concise way to write this? I don't think foldM is what I want -- or is it?
I don't think it can get any more concise. (No, foldM isn't what you want.) But you most probably should prefer the right fold in this case. (Unless you don't care about efficiency.) Something like someA >>= foldr (>=>) return list should do. Roman

Hi!
Although foldM won't make things much nicer, it can be used here as well:
someA >>= \a -> foldM (flip id) a list
Cheers!
Arseniy
On 16 April 2013 13:35, Christopher Howard
So, I'm doing something like this
foldl (>>=) someA list :: Monad m => m a
where list :: Monad m => [a -> m a], someA :: Monad m => m a
Is there a more concise way to write this? I don't think foldM is what I want -- or is it?
-- frigidcode.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (6)
-
Arseniy Alekseyev
-
Christopher Howard
-
Lyndon Maydwell
-
Oliver Charles
-
Roman Cheplyaka
-
Tom Ellis