List comprehensions with Word8

Hello everyone, I was playing with Word8 and list comprehensions and the following examples came up. I have to admit the behavior looks quite strange because it does not seem to be consistent. Can someone shed some light on reason behind some of these outputs? By the way, I have abbreviated some outputs with ellipsis ... [1..10] :: [Word8] [1,2,3,4,5,6,7,8,9,10] [1..100] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,100] [1..1000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,232] [1..10000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] [1..100000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,160] [1..1000000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,64] [1..10000000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,128] [1..100000000] :: [Word8] [] [1..1000000000] :: [Word8] [] Thank you, Jose -- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon

Prelude> 1000000000 `mod` 256
0
So [1..1000000000] == [1..0].
Cheers,
On Thu, May 16, 2013 at 6:15 PM, Jose A. Lopes
Hello everyone,
I was playing with Word8 and list comprehensions and the following examples came up. I have to admit the behavior looks quite strange because it does not seem to be consistent. Can someone shed some light on reason behind some of these outputs?
By the way, I have abbreviated some outputs with ellipsis ...
[1..10] :: [Word8] [1,2,3,4,5,6,7,8,9,10]
[1..100] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,100]
[1..1000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,232]
[1..10000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
[1..100000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,160]
[1..1000000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,64]
[1..10000000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,128]
[1..100000000] :: [Word8] []
[1..1000000000] :: [Word8] []
Thank you, Jose
-- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Felipe.

This happens because of how fromInteger is defined for Word8. It maps
integers to integers mod 256. Also remember that 100000 is actually
fromInteger 100000, in all of your examples.
So your example is actually equivalent to [0..10000 `mod` 256].
On May 16, 2013 2:19 PM, "Jose A. Lopes"
Hello everyone,
I was playing with Word8 and list comprehensions and the following examples came up. I have to admit the behavior looks quite strange because it does not seem to be consistent. Can someone shed some light on reason behind some of these outputs?
By the way, I have abbreviated some outputs with ellipsis ...
[1..10] :: [Word8] [1,2,3,4,5,6,7,8,9,10]
[1..100] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,100]
[1..1000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,232]
[1..10000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,11,12,**13,14,15,16]
[1..100000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,160]
[1..1000000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,64]
[1..10000000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,128]
[1..100000000] :: [Word8] []
[1..1000000000] :: [Word8] []
Thank you, Jose
-- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon
______________________________**_________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, 16 May 2013 23:15:33 +0200, you wrote:
Hello everyone,
I was playing with Word8 and list comprehensions and the following examples came up. I have to admit the behavior looks quite strange because it does not seem to be consistent. Can someone shed some light on reason behind some of these outputs?
When you say <some positive integer> :: [Word8] what you're effectively saying is <some positive integer> `mod` 256 because that's what fits into a slot that's 8 bits wide. So: 1000 `mod` 256 = 232 10000 `mod` 256 = 16 and so on. -Steve Schafer

At risk of belaboring the now-obvious, note that the empty lists begin
at 100000000, which is 10^8, and thus the first power of 10 evenly
divisible by 2^8.
The largest value in the list for each 10^n is likewise 0 modulo 2^n.
(Figuring out why the sequence has those particular multiples of 2^n
is left as an exercise for the reader.)
- C.
On Thu, May 16, 2013 at 5:15 PM, Jose A. Lopes
Hello everyone,
I was playing with Word8 and list comprehensions and the following examples came up. I have to admit the behavior looks quite strange because it does not seem to be consistent. Can someone shed some light on reason behind some of these outputs?
By the way, I have abbreviated some outputs with ellipsis ...
[1..10] :: [Word8] [1,2,3,4,5,6,7,8,9,10]
[1..100] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,100]
[1..1000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,232]
[1..10000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
[1..100000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,160]
[1..1000000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,64]
[1..10000000] :: [Word8] [1,2,3,4,5,6,7,8,9,10,...,128]
[1..100000000] :: [Word8] []
[1..1000000000] :: [Word8] []
Thank you, Jose
-- José António Branquinho de Oliveira Lopes Instituto Superior Técnico Technical University of Lisbon
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Casey McCann
-
Felipe Almeida Lessa
-
Jose A. Lopes
-
Steve Schafer
-
Tikhon Jelvis