[Haskell-beginners] Strange behavior of program
Carsten König
Spam at gettingsharper.de
Sun Mar 8 14:26:24 UTC 2015
No problem - Num can be a bit confusing at first - just make sure to
compare the right things ;)
Am 08.03.2015 um 15:08 schrieb m00nlight:
> Carsten and Arjanen,
>
> Thanks for your explanation. :)
>
>
>
> --m00nlight
>
> 在2015年03月08 20时01分, "arjanen.loic"<arjanen.loic at gmail.com>写道:
>
>
> Hello,
>
> Given that you specifically indicated in your code that you
> wanted Int’s instance of Read and that the result of the product
> is way over 2 ^ 32 (or 2 ^ 64 for that matter), I’d guess the
> difference comes from the fact that the product of a is done with
> type Int (that is, modulo 32 or 64 depending on your computer’s
> CPU architecture) and the product with the litteral list is done
> with type Integer because that the type Haskell defaults to in
> this case.
>
> ARJANEN Loïc Jean David
> http://blog.luigiscorner.com
> ---
> “Computer science is no more about computers than astronomy is
> about telescopes, biology is about microscopes, or chemistry is
> about beakers and test tubes. Science is not about tools. It is
> about how we use them, and what we find out when we do.”
> Michael R. Fellows and Ian Parberry
>
> *De :* m00nlight <mailto:dot_wangyushi at yeah.net>
> *Envoyé :* dimanche 8 mars 2015 21:59
> *À :* The Haskell-Beginners Mailing List - Discussion of primarily
> beginner-level topics related to Haskell
> <mailto:beginners at haskell.org>
>
>
> 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
>
>
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150308/e31c460e/attachment-0001.html>
More information about the Beginners
mailing list