# [Haskell-cafe] more functions to evaluate

Thomas Hartman thomas.hartman at db.com
Fri Oct 12 16:28:18 EDT 2007

```how about this, for wordSize? I used quickcheck to verify that my
wordSize2 is the same as yours.

Actually, it's not! if you allow negative integers in the list, it's not
at any rate. ("falsifiable after 50 tries")

I haven't thought through what this means... if your function isn't quite
right, or mine, or it doesn't really matter.

Also I would be curious to see this quickchecked but not allowing negative
integers in the list if someone can show me how to do that.

Also, I commented out intToBinWord because intToBin isn't in prelude nor
in any library I could track down and I'm not sure what it was supposed to
do.

thomas.

import Data.List
import Data.Maybe
import Test.QuickCheck

wordSize :: [Int] -> Int
wordSize xs = head (dropWhile (<(length xs)) \$ iterate (*2) 8)

wordSize2 :: [Int] -> Int
wordSize2 xs = fromJust \$ find (>(length xs)) \$ iterate (*2) 8

main = quickCheck \$ \xs -> wordSize2 ( xs :: [Int]) == wordSize xs

{-
intToBinWord :: Int -> [Int]
intToBinWord n = reverse (take elements (xs ++ repeat 0))
where
xs = reverse (intToBin n)
elements = wordSize xs
-}

PR Stanley <prstanley at ntlworld.com>
10/12/2007 03:10 PM

To
cc

Subject

Hi folks
Any comments and/or criticisms no matter how trivial on the following

wordSize :: [Int] -> Int
wordSize xs = head (dropWhile (<(length xs)) \$ iterate
(*2) 8)

intToBinWord :: Int -> [Int]
intToBinWord n = reverse (take elements (xs ++ repeat 0))
where
xs = reverse (intToBin n)
elements = wordSize xs

Thanks, Paul

_______________________________________________

---

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
-------------- next part --------------
An HTML attachment was scrubbed...