[Haskell-cafe] RealFloat constraint on Complex type

Henning Thielemann lemming at henning-thielemann.de
Wed May 21 09:08:23 EDT 2008


On Tue, 20 May 2008, Conal Elliott wrote:

> GHC's (maybe Haskell98's?) Complex type is defined with a RealFloat
> constraint on type type itself, rather than on some of the instances and
> functions:
>
>    data (RealFloat a) => Complex a  = !a :+ !a
>
> I think the practice of constraint in type definitions is generally
> discouraged, and I'm wondering if there are reasons other than history for
> having the constraint here.  Is removing it on the table for Haskell'?
>
> I just got bit by what I think is a typical problem.  I added a VectorSpace
> instance for 'Complex a' and discovered that my 'a' must be in RealFloat,
> even though I use only zero, addition, subtraction, and scaling.
>
> I suspect this gripe has been raised before ...

Actually, in NumericPrelude there is no such constraint and Complex is an 
instance of Module and VectorSpace:
   http://darcs.haskell.org/numericprelude/src/Number/Complex.hs
   http://hackage.haskell.org/cgi-bin/hackage-scripts/package/numeric-prelude


More information about the Haskell-Cafe mailing list