<div dir="ltr"><div>This two-step proposal suggests to alter the official Haskell 2010 standard.</div><div><br></div><div>1. Introduction:</div><div><br></div><div>The `Num` typeclass effectively represents a ring. Yet it also has `abs` and `signum`. `abs` represents a norm, but its type is wrong:</div><div><br></div><div>    abs :: a -> a</div><div><br></div><div>Mathematically, the return value must be a nonnegative real number. Yet there is no guarantee that the type `a` can have that value. This led us to have too strong restriction to `instance Num Complex`:</div><div><br></div><div>    instance RealFloat a => Num (Complex a) where ...</div><div><br></div><div>I found a way for `abs` (and `signum`) to have much more mathematical place.</div><div><br></div><div>2. Step 1:</div><div><br></div><div>First, I suggest to add the following variants of `abs` and `signum`:</div><div><br></div><div>    realAbs :: Real a => a -> a</div><div>    realAbs x = if x >= 0 then x else negate x</div><div>    realSignum :: Real a => a -> a</div><div>    realSignum x = case compare 0 x of</div><div>         LT -> -1</div><div>         EQ -> 0</div><div>         _  -> 1</div><div><br></div><div>These can replace `abs` and `signum` instances for integral and rational types.</div><div><br></div><div>3. Step 2:</div><div><br></div><div>Second, I suggest to move `abs` and `signum` from `Num` to `Floating`:</div><div><br></div><div>    class Floating a where</div><div>         abs :: a -> a</div><div>         signum :: a -> a</div><div>         ...</div><div><br></div><div>This exploits the fact that `Floating` represents a field with characteristic 0, regarding exponential and trigonometric functions are defined as Taylor series. The definition of convergence of series is defined using norms.</div><div><br></div><div>4. Conclusion:</div><div><br></div><div>This enables us to implement rings (Num) and fields (Fractional) without concerning about norms. For example, Gaussian integers.<br></div></div>