Bizarre Haskell Problem
Matthew Donadio
m.p.donadio@ieee.org
Mon, 27 Jan 2003 16:34:24 -0500
Hi all,
I am currently a having a bizarre Haskell problem, and was wondering if
anyone had any suggestions.
This is a snippet from a source file:
> foo n = [ a ^* i | i <- [0..(n-2)] ]
> where i ^* j = (i ^ j) `mod` n
> a = generator n
> rader :: Array Int (Complex Double) -> Int -> Array Int (Complex Double)
> rader f n = foo a n -- DEBUG: should be f'
> where h = listArray (0,n-2) [ f!(a ^* (n-(1+n'))) | n' <- [0..(n-2)] ]
> g = listArray (0,n-2) [ w (a ^* n') | n' <- [0..(n-2)] ]
> f' = array (0,n-1) ((0, sum [ f!i | i <- [0..(n-1)] ]) : [ (a ^* i, f!0 + sum [ h!j * g!((i-j)`mod`(n-1)) | j <- [0..(n-2)] ]) | i <- [0..(n-2)] ])
> w i = cis (-2 * pi * fromIntegral i / fromIntegral n)
> i ^* j = (i ^ j) `mod` n
> a = generator n
Under hugs and ghc, calling 'foo' and 'rader' with the proper arguments
will give me different results under certain circumtances.
In rader, n is the number of elements in the array. If n is < 23, then
everything is OK. If n >= 23, then rader returns the wrong result. The
bizarre thing is that if I comment out the definitions of h and f' in
rader, then it returns the correct results. Hugs also give different
reduction counts depending on whether h and f' are commented out or
not. If I add any more definitions that reference f, then rader
misbehaves.
What is even more bizarre is that if I copy everything into a separate
file, then it work for all n.
Any suggestions or hints, other than just use a separate file? Separate
files isn't really an option, because the above is simplified a bit, and
the final version would have mutually recursive modules, which hugs
can't handle.
Thanks.
--
Matthew Donadio (m.p.donadio@ieee.org)