Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Filter to a list of function (Edgar Klerks)
2. FP course @ NICTA (Tony Morris)
3. Re: Filter to a list of function (Igor Pinheiro Le?o)
----------------------------------------------------------------------
Message: 1
Date: Sun, 7 Jul 2013 20:25:22 +0200
From: Edgar Klerks <[email protected]>
Subject: Re: [Haskell-beginners] Filter to a list of function
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<cagauytnwhecmgmwpq1hdersktkufimeyhfr_t_d+zvzvzbz...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
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 <[email protected]>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
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130707/1486d2a0/attachment-0001.htm>
------------------------------
Message: 2
Date: Mon, 08 Jul 2013 11:12:26 +1000
From: Tony Morris <[email protected]>
Subject: [Haskell-beginners] FP course @ NICTA
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hello,
The National ICT of Australia is offering a two day functional
programming course in Sydney, Australia in late August. There is no cost
involved. If you are interested, please join the mailing list linked
below and answer a couple of questions. We will be responding to
expressions of interest later this week. Thanks!
https://groups.google.com/forum/#!msg/nicta-fp/rQLXgvg9SQY/YnkIMg3OVFkJ
--
Tony Morris
http://tmorris.net/
------------------------------
Message: 3
Date: Sun, 7 Jul 2013 23:12:17 -0300
From: Igor Pinheiro Le?o <[email protected]>
Subject: Re: [Haskell-beginners] Filter to a list of function
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAGrJ+gf=ch_g6t9agr6mpq2fkcr1ns0ksknrefcj+0rqm4z...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Thank you Edgar!
2013/7/7 Edgar Klerks <[email protected]>
> 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 <[email protected]>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
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--
Igor Vin?cius
Graduando em Ci?ncia da Computa??o
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130707/6115059b/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 61, Issue 10
*****************************************