> I am having a bizarre Haskell problem that I am having difficulty
> debugging.  I am not positive this is a compiler problem, but 
> my results
> are not making any sense.
> 
> I have attached a few source files which compiled with ghc-5.04.2
> running under Win95.  The files were compiled as:
> 
> ghc -c DFT.lhs
> ghc -c FFT1.lhs
> ghc -c FFT2.lhs
> ghc -c Main1.hs
> ghc -c Mail2.hs
> ghc -o test1 Main1.o FFT1.o DFT.o
> ghc -o test2 Main2.o FFT2.o DFT.o
> 
> Running test1 gives the following results (the last line is wrong):
> 
> foo 19:    [1,2,4,8,16,13,7,14,9,18,17,15,11,3,6,12,5,10]
> rader1 19: [1,2,4,8,16,13,7,14,9,18,17,15,11,3,6,12,5,10]
> foo 23:    [1,5,2,10,4,20,8,17,16,11,9,22,18,21,13,19,3,15,6,7,12,14]
> rader1 23: [1,5,2,10,4,20,8,17,16,11,9,22,18,21,1,4,8,18,22,6,19,2]
> 
> Running test2 gives the following results (these are the results I
> expect):
> 
> foo 19:    [1,2,4,8,16,13,7,14,9,18,17,15,11,3,6,12,5,10]
> rader1 19: [1,2,4,8,16,13,7,14,9,18,17,15,11,3,6,12,5,10]
> foo 23:    [1,5,2,10,4,20,8,17,16,11,9,22,18,21,13,19,3,15,6,7,12,14]
> rader1 23: [1,5,2,10,4,20,8,17,16,11,9,22,18,21,13,19,3,15,6,7,12,14]

Your problem is that rader1 has different types in FFT1 and FFT2:

   ___         ___ _
  / _ \ /\  /\/ __(_)
 / /_\// /_/ / /  | |      GHC Interactive, version 5.04.2, for Haskell
98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Loading package haskell98 ... linking ... done.
:Prelude> :l FFT1
Skipping  DFT              ( DFT.lhs, DFT.o )
Skipping  FFT1             ( FFT1.lhs, ./FFT1.o )
Ok, modules loaded: FFT1, DFT.
Prelude FFT1> :t rader1
forall a b.
(Integral a,
 GHC.Arr.Ix a,
 Num (Data.Complex.Complex b),
 RealFloat b) =>
GHC.Arr.Array a (Data.Complex.Complex b) -> a -> [a]
Prelude FFT1> :t rader1 (gendata 23) 23
[Int]
Prelude FFT1> :l FFT2
Skipping  DFT              ( DFT.lhs, DFT.o )
Skipping  FFT2             ( FFT2.lhs, ./FFT2.o )
Ok, modules loaded: FFT2, DFT.
Prelude FFT2> :t rader1
forall a t. (Integral a, GHC.Arr.Ix a) => t -> a -> [a]
Prelude FFT2> :t rader1 (gendata 23) 23 
forall a. (Integral a, GHC.Arr.Ix a) => [a]

So in FFT2, defaulting will force the type variable a to Integer,
whereas in FFT1 the type has already been forced to Int.  I imagine that
with Int you're getting some overflow, leading to the incorrect results.

Moral of this story: type signatures can help to avoid unexpected
behaviour...

Cheers,
        Simon
_______________________________________________
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to