
Hi Guys, 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. Kind regards, Igor -- Igor Vinícius Graduando em Ciência da Computação

Hum.. really sorry about the grammar mistakes.
2013/7/7 Igor Pinheiro Leão
Hi Guys, 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.
Kind regards, Igor
-- Igor Vinícius Graduando em Ciência da Computação
-- Igor Vinícius Graduando em Ciência da Computação

But lists only contain one type, so I am not sure what you want to do here.
Get elements that are true for all filters? For at least one filter? There
is no sub typing relationship...
On 7 Jul 2013 18:34, "Igor Pinheiro Leão"
Hum.. really sorry about the grammar mistakes.
2013/7/7 Igor Pinheiro Leão
Hi Guys, 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.
Kind regards, Igor
-- Igor Vinícius Graduando em Ciência da Computação
-- Igor Vinícius Graduando em Ciência da Computação
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

No need to apologize for grammar. =) There are lots of people in the Haskell community with many different levels of English fluency, we all just try to communicate as best we can. As for your question, I am not quite sure I understand what you want. Do you mean that you want to "zip" the lists together, applying each function to one element? As in specificFilter [(>3), even, (<19)] [6, 7, 8] = [6,8] because 6>3 and 8>19 (but 7 is not even)? If that is what you mean, then you could do something like specificFilter ps xs = map snd . filter fst $ zipWith (\p x -> (p x, x)) ps xs If you mean something else, then maybe you could give some examples of what you want? -Brent On Sun, Jul 07, 2013 at 02:32:21PM -0300, Igor Pinheiro Leão wrote:
Hum.. really sorry about the grammar mistakes.
2013/7/7 Igor Pinheiro Leão
Hi Guys, 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.
Kind regards, Igor
-- Igor Vinícius Graduando em Ciência da Computação
-- Igor Vinícius Graduando em Ciência da Computação
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Thank you Benjamin and Brent!
Brent, yes, that was exactly what i wanted to do. Thank you!
Kind regards,
Igor
2013/7/7 Brent Yorgey
No need to apologize for grammar. =) There are lots of people in the Haskell community with many different levels of English fluency, we all just try to communicate as best we can.
As for your question, I am not quite sure I understand what you want. Do you mean that you want to "zip" the lists together, applying each function to one element? As in
specificFilter [(>3), even, (<19)] [6, 7, 8] = [6,8]
because 6>3 and 8>19 (but 7 is not even)?
If that is what you mean, then you could do something like
specificFilter ps xs = map snd . filter fst $ zipWith (\p x -> (p x, x)) ps xs
If you mean something else, then maybe you could give some examples of what you want?
-Brent
On Sun, Jul 07, 2013 at 02:32:21PM -0300, Igor Pinheiro Leão wrote:
Hum.. really sorry about the grammar mistakes.
2013/7/7 Igor Pinheiro Leão
Hi Guys, 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.
Kind regards, Igor
-- Igor Vinícius Graduando em Ciência da Computação
-- 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
-- Igor Vinícius Graduando em Ciência da Computação

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) where
mempty = Filter $ const True
mappend (Filter a) (Filter b) = Filter $ \x -> a x && b x
andF :: Filter a -> Filter a -> Filter a
andF = mappend
-- We can also create or
orF :: Filter a -> Filter a -> Filter a
orF (Filter a) (Filter b) = Filter $ \x -> a x || b x
mkFilter :: (a -> Bool) -> Filter a
mkFilter = Filter
-- Some example filters
evenFilter = mkFilter even
lessThanHundred = mkFilter (<100)
specificFilter :: Filter a -> [a] -> [a]
specificFilter xs ys = filter (runFilter xs) ys
-- get less then hundred and even
testa = specificFilter (evenFilter <> lessThanHundred) [1..1000]
-- get less then hundred or even
testb = specificFilter (evenFilter `orF` lessThanHundred) [1..1000]
Cheers,
Edgar
On Sun, Jul 7, 2013 at 7:26 PM, Igor Pinheiro Leão
Hi Guys, 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.
Kind regards, Igor
-- Igor Vinícius Graduando em Ciência da Computação
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Thank you Edgar!
2013/7/7 Edgar Klerks
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) where mempty = Filter $ const True mappend (Filter a) (Filter b) = Filter $ \x -> a x && b x
andF :: Filter a -> Filter a -> Filter a andF = mappend
-- We can also create or orF :: Filter a -> Filter a -> Filter a orF (Filter a) (Filter b) = Filter $ \x -> a x || b x
mkFilter :: (a -> Bool) -> Filter a mkFilter = Filter
-- Some example filters evenFilter = mkFilter even lessThanHundred = mkFilter (<100)
specificFilter :: Filter a -> [a] -> [a] specificFilter xs ys = filter (runFilter xs) ys
-- get less then hundred and even testa = specificFilter (evenFilter <> lessThanHundred) [1..1000]
-- get less then hundred or even testb = specificFilter (evenFilter `orF` lessThanHundred) [1..1000]
Cheers,
Edgar
On Sun, Jul 7, 2013 at 7:26 PM, Igor Pinheiro Leão
wrote: Hi Guys, 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.
Kind regards, Igor
-- 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
-- Igor Vinícius Graduando em Ciência da Computação
participants (4)
-
Benjamin Edwards
-
Brent Yorgey
-
Edgar Klerks
-
Igor Pinheiro Leão