[Haskell-beginners] putting together monadic actions

Sylvain Henry sylvain at haskus.fr
Wed Aug 24 01:33:01 UTC 2016


Hi,

You can easily write your own:

 > import Control.Monad
 > import Data.List
 > let foo = flip (foldl' (>=>) return)
 > :t foo
foo :: (Foldable t, Monad m) => b -> t (b -> m b) -> m b
 > let g x = return (x*2)
 > foo 3 [g,g,g]
24

-Sylvain


On 24/08/2016 03:00, Dennis Raddle wrote:
> Is there a function foo that does
>
> foo :: a -> [a -> m a] -> a
>
> So
>
> foo 3 [x,x,x] = return 3 >>= x >>= x >>= x
>
> I don't think replicateM and sequence do this. At least I can't figure 
> it out.
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160824/ece8623d/attachment-0001.html>


More information about the Beginners mailing list