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

Harald Bögeholz bo at ct.de
Tue Dec 31 20:34:44 UTC 2013


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    <bo at ct.de> (PGP key available from servers)
Redaktion c't      Tel.: +49 511 5352-300  Fax: +49 511 5352-417
                   http://www.ct.de/

                   int f[9814],b,c=9814,g,i;long a=1e4,d,e,h;
                   main(){for(;b=c,c-=14;i=printf("%04d",e+d/a),e=d%a)
                   while(g=--b*2)d=h*b+a*(i?f[b]:a/5),h=d/--g,f[b]=d%g;}
                                                          (Arndt/Haenel)

                   Affe Apfel Vergaser

/* Heise Zeitschriften Verlag GmbH & Co. KG * Karl-Wiechert-Allee 10 *
   30625 Hannover * Registergericht: Amtsgericht Hannover HRA 26709 *
   Persönlich haftende Gesellschafterin: Heise Zeitschriften Verlag *
   Geschäftsführung GmbH * Registergericht: Amtsgericht Hannover, HRB
   60405 * Geschäftsführer: Ansgar Heise, Dr. Alfons Schräder */


More information about the Beginners mailing list