[Haskell-beginners] How to get each list in a list of lists for filter
Angus Comber
anguscomber at gmail.com
Tue Dec 31 18:48:59 UTC 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20131231/e4a637b8/attachment.html>
More information about the Beginners
mailing list