[Haskell-cafe] Re: Specify array or list size?

Max Vasin max-appolo at mail.ru
Sat May 7 12:05:10 EDT 2005


Daniel Carrera <dcarrera at digitaldistribution.com> writes:

> Max Vasin wrote:
>
>> But why do you need that? Where do need to make an assumption about the size
>> of the list? 
>
> I'm implementing the RC4 algorithm, which requires a state array with
> 256 elements containing the bytes from 0 to 255. As the algorithm
> progresses, the elements of the array get shuffled around. This is
> what drives the pseudo-random number generator. But the size of the
> state array is always 256.
So, you need list of length 256 and then just use it as state of your PRNG.
If you want to check list size you have to do it at runtime:

f lst | length lst == 256 -> doWork
      | otherwise         -> fail "length lst must be 256"

--
WBR,
Max Vasin.



More information about the Haskell-Cafe mailing list