[Haskell-cafe] convergence of functions of Complex variables

Ross Paterson ross at soi.city.ac.uk
Wed Dec 15 05:28:18 EST 2004


On Wed, Dec 15, 2004 at 02:07:10AM -0800, William Lee Irwin III wrote:
> This does not work as expected on Complex numbers due to some odd
> typechecking hassles apparently associated with abs. How do I get this
> to typecheck for both real (e.g. Double) and Complex arguments?

abs :: Num a => a -> a, whereas you want something that returns a Double.
You could define

class Norm a where
        norm :: a -> Double

instance Norm Float where
        norm = realToFrac . abs

instance Norm Double where
        norm = abs

instance RealFloat a => Norm (Complex a) where
        norm = realToFrac . magnitude

and use norm instead of abs.


More information about the Haskell-Cafe mailing list