On 5/23/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm new to Haskell and even newer to this list. I have over 20 years of > experience in C or C++. > > For fun, I decided to write a Fourier transform in Haskell. It would be > convenient if I had a function that converts any real or complex number into > a complex number. My attempt at doing this is below. Hugs produces errors > when I try to load this code. > > Essentially, I'm trying to define a class called ConvertibleToComplex. > There is a function in this class called toComplex. toComplex has the type: > > class ConvertibleToComplex a where > toComplex :: RealFloat b => a -> Complex b
I don't think you want an arbitrary type 'b'. Try: (pass -98 to Hugs or -fglasgow-exts to GHCi when loading this code) import Complex class ConvertibleToComplex a b | a -> b where toComplex :: RealFloat b => a -> Complex b instance ConvertibleToComplex Float Float where toComplex f = f :+ 0 instance ConvertibleToComplex Double Double where toComplex d = d :+ 0 instance ConvertibleToComplex (Complex a) a where toComplex c = c -- Friendly, Lemmih _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe