>I'm building it now, so I'll hopefully have some results later today.
If this helps (applies to linux-2.2.10, glibc-2.1.1, libgpm-2.0.2, compiled as
shared libs, AMD K6-II):
- As I've already said, using a egcs-1.1.2 compiled ghc-4.04 seems to work
fine, even with gcc-2.95 used as the C compiler for my own (simple) programs.
- ghc-4.04 compiled by gcc-2.95 produces for my example programs (see below)
the same code (.hc files and even .s files) as ghc-4.04 compiled by egcs-1.1.2.
However, the linked program doesn't work -- hamming 3 prints just 0's instead
of the expected hamming numbers 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ... It
seems that there is a problem with the libraries that come along with ghc; the
compiler seems to be ok -- at least for hamming.
- An even simpler program that only calculates and print prime numbers
instead of hamming numbers is ok.
- I tried to compile ghc and it's libraries using gcc -fno-strict-aliasing
(since this may be a problem), but it doesn't help, so you don't have to try
this options to find the error.
Here is the example program, which consists of three modules, Primes, Hamming
and HammingMain:
Primes.hs:
==========
module Primes (primes) where
primes :: Integral a => [a]
primes = sieve [2..] where
sieve (p:xs) = p : sieve (xs /// iterate (+p) p)
xs@(x:xs') /// ys@(ys:ys') | x < y = x : xs' /// ys
| x > y = xs /// ys'
| otherwise = xs' /// ys'
-- Yes, I know that I should use compare instead of (<) and (>) :-)
Hamming.hs:
===========
module Hamming (hamming) where
import Primes
hamming n = 1 : products [ iterate (*x) x | x <- take n primes ]
products [xs] = xs
products (xs:xss) = merge (xs : [map (*x) (products xss) | x <- 1 : xs])
merge ((x:xs):xss) = x : merge (resort xs xss)
resort xs@(x:_) yss@(ys@(y:_):yss') | x <= y = xs : yss
| otherwise = ys : resort xs yss'
HammingMain.hs:
===============
module Main (main) where
import IO
import System
import Hamming
usage:: IO ()
usage = do
hPutStr stderr "usage: blahblah\n" exitFailure
main :: IO ()
main = do
args <- getArgs
case args of
[ps] -> do p <- readIO ps
printlines ((hamming p) :: [Integer])
[ps, ns] -> do p <- readIO ps
n <- readIO ns
let hs = hamming p
putStrLn (show (hs !! (n - 1)))
_ -> usage
where
printlines [] = return ()
printlines (x:xs) = do putStrLn (show x)
printlines xs
Don't think about the use oft his program. AFAIK there is no practical
application for hamming numbers.
Bye,
Kili