Splitting SYB from the base package in GHC 6.10
Jules Bean
jules at jellybean.co.uk
Fri Sep 5 08:34:47 EDT 2008
José Pedro Magalhães wrote:
> Complex has a derived instance. In Data.Complex:
>
> data (RealFloat a) => Complex a
> = !a :+ !a
> # if __GLASGOW_HASKELL__
> deriving (Eq, Show, Read, Data)
> # else
> deriving (Eq, Show, Read)
> # endif
>
> Was there a problem with this?
>
Yes, isn't it exactly the same problem as Ratio?
The derived instance 'leaks' the implementation detail of a complex
number as a real and imaginary component. As part of a large structure I
might want to apply some operation to all the 'Doubles' therein, but
certainly not to the components of any Complex Doubles. You can imagine
particular situations where I want to apply only to the real component,
or something more subtle.
You can also imagine that an alternative implementation of Complexes in
polar coordinates (with a suitable solution to the principle value
problem) is supposed to be abstractly the same, but would gain a totally
different Data instance.
Jules
More information about the Libraries
mailing list