How to get each list in a list of lists for filter

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

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
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@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Am 31.12.13 19:48, schrieb Angus Comber:
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.
Could a simple typo be the problem?
Shouldn't chop9 .. take 9 bits ... and ... drop 9 bits ... instead of 8?
Harald
--
Harald Bögeholz
participants (3)
-
Angus Comber
-
divyanshu ranjan
-
Harald Bögeholz