[Haskell-beginners] How to get each list in a list of lists for filter

divyanshu ranjan idivyanshu.ranjan at gmail.com
Tue Dec 31 18:57:07 UTC 2013


Hi Angus,
    Try placing $ in place of ???.  Type of filter is (a->Bool) -> [a] ->
[a]. $ is of type (a->b) -> a -> b  but it's low priority so left and right
hand side is calculated before function application.

Thanks
Divyanshu Ranjan


On Wed, Jan 1, 2014 at 12:18 AM, Angus Comber <anguscomber at gmail.com> wrote:

> I am getting a list of lists from chop9.  I want to somehow filter each
> element in the list.  How do I do that.
>
> I have encoded binary data eg [1,1,0,0,1,0] etc
>
> Each 9th bit is a parity bit which is checked using this function:
>
> type Bit = Int
>
> paritychecker :: [Bit] -> Bool
> paritychecker xs | length xs == 9 && ((sum (init xs)) `mod` 2) == (last
> xs) = True
>                  | otherwise = False
>
>
> In the stream (the list) I use chop to retrieve each block of 9 bits as in:
>
> chop9 :: [Bit] -> [[Bit]]
> chop9 [] = []
> chop9 bits = take 8 bits : chop9 (drop 8 bits)
>
> I have been playing with this sort of thing:
> filter paritychecker ??? chop9 [1,0,0,0,1,1,1,0,0,...]
>
>  But doesn't work.
>
> I want to end up with all the 9 bit chunks which pass the filter.  So my
> end type should be [[Bit]]
>
> paritychecker requires a list - eg [Bit] . So I want to run paritychecker
> on each element returned from chop9.  How do I do that?
>
> Example encoded data stream:
>
> [1,0,0,0,1,1,1,0,0,1,1,1,0,1,1,1,0,0,1,0,1,0,0,1,1,0,0,0,1,0,0,1,1,1,0,0,0,0,1,0,1,1,1,0,0,1,0,0,1,1,1,1,0,1]
>
> Angus
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140101/9476bfd1/attachment-0001.html>


More information about the Beginners mailing list