[Haskell-cafe] Things to avoid (Was: Top 20 ``things'' to know in Haskell)

Iavor Diatchki iavor.diatchki at gmail.com
Fri Feb 11 12:58:43 EST 2005


Hi,

On Fri, 11 Feb 2005 12:02:56 +0100, Thomas Jäger <thjaeger at gmail.com> wrote:
>
> iii) As a side effects of how n+k patterns work, each instance of the
> Num class must also be an instance of Eq, which of course doesn't make
> sense for all numeric types.

Well this is not entirely true.  I don't think 'n+k' patterns need
equality, but they need ordering
f (n + k) = e
is like:
f x | x > k = let n = x - k in e

Literal patterns need equality:
f 2 = e
is like:
f x | x == 2 = e

These do not force the 'Num' class to be a superclass of 'Ord' or
'Eq'.  If 'Num' was not a superclass of 'Eq', whenver you used a
literal pattern there would be an extra constraint that there should
be equality on the corresponding type. For example:
f 2 = "Hello"
would get the type:
f :: (Eq a, Num a) => a -> String

Hope this helps
-Iavor


More information about the Haskell-Cafe mailing list