[Haskell-beginners] question about any

Manfred Lotz manfred.lotz at arcor.de
Thu Dec 29 06:45:27 CET 2011


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




More information about the Beginners mailing list