Haskell Prime: Ticket Query
http://ghc.haskell.org/trac/haskell-prime/query?status=!closed&keywords=~Numeric&order=priority
Haskell Primeen-USHaskell Prime/images/HaskellLogo_2.jpg
http://ghc.haskell.org/trac/haskell-prime/query?status=!closed&keywords=~Numeric&order=priority
Trac 1.0.7
http://ghc.haskell.org/trac/haskell-prime/ticket/112
http://ghc.haskell.org/trac/haskell-prime/ticket/112#112: Break unnecessary dependencies between Haskell numeric classesWed, 20 Sep 2006 19:51:39 GMTguest<p>
Motivation:
</p>
<p>
The Haskell numeric classes contain some interdependencies that look rather odd to a mathematician. For example, why do you have to be Show in order to be Num, and why do you have to be Enum in order to be Integral. These dependencies are not justified by mathematical considerations, and make it hard to represent some mathematical concepts in Haskell.
</p>
<p>
For example, consider the Gaussian integers - numbers of the form a+bi, where a and b are integers, and i is the square root of -1. (Complex Integer, if you like.) There is a division with remainder algorithm for the Gaussian integers, so that we would like to declare them as an instance of Integral, and define the quotRem function. However, to do this we would have to declare them as an instance of Enum - and this makes no sense - there is no natural way to define the Enum functions on the Gaussian integers.
</p>
<p>
For similar reasons, the dependency of Integral on Real is suspect - there is no natural way to define toRational on the Gaussian integers.
</p>
<p>
The dependency of <a class="missing wiki">RealFrac?</a> on Fractional is also unnecessary - what have floor, ceiling etc got to do with recip?
</p>
<p>
Note that breaking these dependencies will not break any existing code. At present, if I declare a type T to be a Num instance, I must also declare it to be an Eq instance and a Show instance. If the dependency is broken, that is, if
</p>
<p>
class (Eq a, Show a) => Num a
</p>
<p>
is replaced by
</p>
<p>
class Num a
</p>
<p>
then existing code will still work.
</p>
<p>
What will have changed is that it will now be possible to declare a type T to be a Num instance without also declaring it to be an Eq and a Show instance.
</p>
<p>
Proposal:
</p>
<p>
Conservative version:
</p>
<p>
Replace the existing Prelude class declarations with:
</p>
<ol><li>class Eq a => Num a -- remove dependency on Show
</li></ol><ol start="2"><li>class Num a => Integral a -- replace dependency on Real, Enum by dependency on Num
</li></ol><ol start="3"><li>class Real a => <a class="missing wiki">RealFrac?</a> a -- remove dependency on Fractional
</li></ol><p>
Radical version:
</p>
<p>
In addition to the above:
</p>
<ol start="4"><li>Split abs and signum out from Num into a new
</li></ol><p>
class Num a => Quantity a
</p>
<p>
(There are plenty of objects in mathematics for which the arithmetical operations +,-,* make sense, but the size and direction operations abs and signum do not - for example polynomials, matrices.)
</p>
<ol start="5"><li>Amalgamate classes Real and <a class="missing wiki">RealFrac?</a> - Real no longer has any purpose as a distinct class. The new class should probably be called Real.
</li></ol><p>
See also: <a class="wiki" href="http://ghc.haskell.org/trac/haskell-prime/wiki/NumericClasses">NumericClasses</a>.
</p>
Resultshttp://ghc.haskell.org/trac/haskell-prime/ticket/112#changelog