[Haskell-beginners] Strange behavior of program
m00nlight
dot_wangyushi at yeah.net
Sun Mar 8 10:59:57 UTC 2015
Hi Haskellers,
I encounter an strange behavior of haskell program recently. The following is my program
```haskell
main = do
_ <- getLine
arr1 <- getLine
_ <- getLine
arr2 <- getLine
let a = map (read :: String -> Int) (words arr1)
b = map (read :: String -> Int) (words arr2)
putStrLn $ show $ (foldl (*) 1 a)
putStrLn $ show $ a == [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192]
putStrLn $ show $ (foldl (*) 1 [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192])
```
With the input test file as following:
```test.in
13
1 2 4 8 32 64 128 256 512 1024 2048 4906 8192
9
1 3 9 27 81 243 729 2187 6561
```
The output is as:
```output
0
True
185343439719667835347140608
```
In fact, from the program, we know that a is equal to list [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] ,
but the product of a and the literal list is different.
Can anyone tell me why?
Thanks
--m00nlight
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150308/27bf09ca/attachment-0001.html>
More information about the Beginners
mailing list