[Haskell-beginners] question about any

Tim Baumgartner baumgartner.tim at googlemail.com
Thu Dec 29 08:29:41 CET 2011


2011/12/29 Manfred Lotz <manfred.lotz at arcor.de>

> Hi there,
> might be trivial but anyway.
>
> I have a usage of 'any' and 'all' but I only have a predicate
> p :: a -> IO Bool.
>
> I wrote my own functons for this:
>
>
> mor :: Monad m => [m Bool] -> m Bool
> mor = liftM or . sequence
>
> mand :: Monad m => [m Bool] -> m Bool
> mand = liftM and . sequence
>
> or' :: Monad m => ( a -> m Bool) -> [a] -> [m Bool]
> or' _ [] = []
> or' p (x:xs) = p x : or' p xs
>
> and' :: Monad m => ( a -> m Bool) -> [a] -> [m Bool]
> and' _ [] = []
> and' p (x:xs) = p x : and' p xs
>
> myany :: Monad m => (a -> m Bool) -> [a] -> m Bool
> myany p = mor . or' p
>
> myall :: Monad m => (a -> m Bool) -> [a] -> m Bool
> myall p = mand . and' p
>
>
> which seems to do what I want.
>
>
> Question: Is there any libray function I could use to do this?
>
>
> --
> Thanks,
> Manfred
>

Hi Manfred,

have a look here:
http://hackage.haskell.org/packages/archive/monad-loops/latest/doc/html/Control-Monad-Loops.html#v:allM

Regards Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111229/2f8ad4ea/attachment.htm>


More information about the Beginners mailing list