[Haskell] Strictness question
Ben Lippmeier
Ben.Lippmeier at anu.edu.au
Tue Jun 7 05:43:48 EDT 2005
Gary Morris wrote:
>>ioexptmod :: Integer -> Integer -> Integer -> Int -> IO Integer
>>ioexptmod base expt n keySize = return $! exptmod base expt n keySize
> My hope was that the use
> of $! would force it to compute the exponentiation while I was timing
> -- and the average times are around 30K clock cycles, suggesting that
> it's doing the work, but I was wondering if it was possible that I was
> missing something.
An expression like (f $! x) is only ever going to force x to whnf (weak
head normal form).
To gloss over details: it'll reduce x far enough so it knows that it's
an Integer, but it won't nessesarally compute that integers value.
If you want to ensure that something is actually computed in a lazy
language, you need to do something with the result that *absolutely*
needs a completely constructed object.. Printing to screen is a prime
candidate, the system can't print something unless it's evaluated it.
Those 30K clocks suggest it's doing _some_ work. I wouldn't start making
bets on what that work actually consists of though..
BTW: Haskell would have to be my absolutely last choice for
experimenting with timing attacks against RSA.. Let's just say that I
admire your courage! :)
Ben.
More information about the Haskell
mailing list