[Haskell-beginners] filterM function

Magnus Therning magnus at therning.org
Wed Apr 22 08:41:11 UTC 2015


On 22 April 2015 at 10:31, Shishir Srivastava
<shishir.srivastava at gmail.com> wrote:
> Hi,
>
> Continuing on from my previous question about powerset using filterM -
> Thanks to Alexey and Chaddaï.
>
> filterM is implemented as below -
>
> ----
>
> filterM _ []     =  return []
> filterM p (x:xs) =  do
>    flg <- p x
>    ys  <- filterM p xs
>    return (if flg then x:ys else ys)
>
> ---
>
> I still don't quite understand how 'flg' being a boolean [] is used in the
> last 'if statement' of implementation because when I try to do the same
> thing outside in GHCi it fails miserably even though I am casting it to
> [Int] -
>
> --
> return (if [True, False] then "4" else "3")::[Int]
> --

`flg` has type `Bool`, not `[Bool]`.

> Offtopic : Also if someone can explain how do I reply to individual
> mails/responses to my queries because I only get a digest on my gmail and
> there is no way to isolate and reply to individual mails either this list's
> page or from digest.

I suspect you'll have to go to the list server and modify your
settings there; it sounds like you have instructed it to send digests,
so you need to change it to send every individual email.

Alternatively you switch to a more capable mail reader, e.g. mutt,
which handles digests better than gmail does.

/M

-- 
Magnus Therning                      OpenPGP: 0xAB4DFBA4
email: magnus at therning.org   jabber: magnus at therning.org
twitter: magthe               http://therning.org/magnus


More information about the Beginners mailing list