What's difference between Integer and Int?
Hello glasgow-haskell-users, The following program --- --main = print (show (fibs!!20)) main = print (show (nth 20 fibs)) nth 0 (h:_) = h nth n (h:t) = nth (n-1) t fibs :: [Integer] -- fibs = 1 : (map snd $ iterate (\(x,y) - (y, x+y)) (1,1)) fibs = [1..] --- compiled with ghc 6.0: ghc -O -o a.exe a.hs does not execute correctly. It causes stack overflow in 1M stack. If we change fibs :: [Integer] to fibs :: [Int] the new program runs Ok. -- Best regards, Serguey mailto:[EMAIL PROTECTED] ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: What's difference between Integer and Int?
Hi Serguey! On Tue, Aug 19, 2003 at 03:14:53PM -0700, Serguey Zefirov wrote: Hello glasgow-haskell-users, The following program --- --main = print (show (fibs!!20)) main = print (show (nth 20 fibs)) nth 0 (h:_) = h nth n (h:t) = nth (n-1) t fibs :: [Integer] -- fibs = 1 : (map snd $ iterate (\(x,y) - (y, x+y)) (1,1)) fibs = [1..] --- compiled with ghc 6.0: ghc -O -o a.exe a.hs does not execute correctly. It causes stack overflow in 1M stack. If we change fibs :: [Integer] to fibs :: [Int] the new program runs Ok. I was confused by that at first, too. This is caused by the way [1..] works. `nth 20 [1..]' returns the expression `1+1+1+1+1+1+1+...+1' and evaluating that causes the stack overflow. For Ints the additions are apparently carried out during the construction of [1..], probably because they are considered cheap. You can fix this by using === elementStrict :: [a] - [a] elementStrict = foldr (($!) (:)) [] === and replacing [1..] by (elementStrict [1..]). With that, the following program will also work. === module Main(main) where main = print (fibs!!20) fibs :: [Integer] fibs = 1 : elementStrict (map snd $ iterate (\(x,y) - (y, x+y)) (1,1)) === It produces a result with 41798 decimal digits. Greetings, Carsten -- Carsten Schultz (2:40, 33:47), FB Mathematik, FU Berlin http://carsten.fu-mathe-team.de/ PGP/GPG key on the pgp.net key servers, fingerprint on my home page. pgp0.pgp Description: PGP signature
GHC 6.0.1 for Mac OS X available through darwinports
Hello, GHC 6.0.1 for Mac OS X is now available through the darwinports system. Darwinports is similar to the *BSD port system. It downloads and builds both the target and dependencies automatically for your machine. Note that darwinports is still under development. OS X users who want a simple, reliable installation should use Wolfgang Thaller's GHC disk image. The darwinports version is aimed at people who want to build from source. If you have suggestions for particular customizations, let me know. Darwinports has support for 'variant' builds that make customization easy. For more information on darwinports, and to download the infrastructure, see http://www.opendarwin.org/projects/darwinports/ Best Wishes, Greg Wright Gregory Wright Antiope Associates 18 Clay Street Fair Haven, New Jersey 07704 USA [EMAIL PROTECTED] ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Hash functions
Many thanks for Data.HashTable, which I am about to use. Unfortunately I seem to need an unseemly hack because the key I want, namely ThreadId's, don't have a hash function defined, and defining one requires me to muck around with GHC internal functions. Could some more hash functions be provided? The logical method would be to have class HashKey key where hash :: key - Int32 and define it for as many types as possible. ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users