Hi Igor,You can create a new type for a -> Bool with which you can compose to create complex filters. I find that an elegant approach:import Data.Monoid
newtype Filter a = Filter {runFilter :: a -> Bool}-- We can turn filter into a monoid, behaving like and.instance Monoid (Filter a) wheremempty = Filter $ const Truemappend (Filter a) (Filter b) = Filter $ \x -> a x && b xandF :: Filter a -> Filter a -> Filter aandF = mappend-- We can also create ororF :: Filter a -> Filter a -> Filter aorF (Filter a) (Filter b) = Filter $ \x -> a x || b xmkFilter :: (a -> Bool) -> Filter amkFilter = Filter-- Some example filtersevenFilter = mkFilter evenlessThanHundred = mkFilter (<100)specificFilter :: Filter a -> [a] -> [a]specificFilter xs ys = filter (runFilter xs) ys-- get less then hundred and eventesta = specificFilter (evenFilter <> lessThanHundred) [1..1000]-- get less then hundred or eventestb = specificFilter (evenFilter `orF` lessThanHundred) [1..1000]Cheers,EdgarOn Sun, Jul 7, 2013 at 7:26 PM, Igor Pinheiro Leão <ivpcl@cin.ufpe.br> wrote:
IgorHi Guys,Kind regards,
sorry in upsetting you again.
Is there a way in which I can filter one list of function, one function at time, to a list of elements, declaring this and only this function.
It would be exactly like this:
specifcFilter :: [(a->Bool)] -> [a] -> [a]
where for each element of type 'a' on the second list it would exist a function on the first list that would be applied to it filtering.
--
Igor Vinícius
Graduando em Ciência da Computação
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners