[Haskell] Num is such a fat and greedy class

David House dmhouse at gmail.com
Sat Dec 9 16:21:32 EST 2006


On 08/12/06, Dan Weston <westondan at imageworks.com> wrote:
> The following observations are not new, insightful, or gracious, but I
> Wouldn't the following be more useful/general?
>
> class Subtraction a b | a -> b where
>   (-) :: a -> a -> b

If you split them up like this, things like quadRoots take an
unwieldly type signature:

quadRoots a b c | a /= 0 = (x1 / (2*a), x2 / (2*a))
  where x1 = -b - sqrt det
       x2 = -b + sqrt det
       det = b ^ 2 - 4*a*c

As these use many of the operations. However, this might become
manageable with class aliases [1].

[1]: http://repetae.net/john/recent/out/classalias.html

-- 
-David House, dmhouse at gmail.com


More information about the Haskell mailing list