[Haskell-cafe] what I learnt from my first serious haskell
fmohamed at mac.com
Mon Mar 19 13:26:33 EDT 2007
David House wrote:
> On 19/03/07, Fawzi Mohamed <fmohamed at mac.com> wrote:
>> This is is very ugly in my opinion, because for me a type class should
>> represent something more than just a way to overload, is something is
>> not a number then it should not have the class Num.
> Num is a collection of types whose members can be added and subtracted
> and so on. As numbers are the most common example of this, one could
> say the members of Num _act like numbers_, rather than are numbers in
> Really typeclasses are all about overloading. For example, Eq is the
> collection of types that the equality predicate (==) applies to. I
> don't see this as ugly; quite the contrary, in that if you know a type
> instantiates Eq you can use (==) without worrying about using a
> type-specific equality predicate. E.g. it's nice to see the same (==)
> everywhere rather than seeing (say) (Int.==), (Bool.==) and so on.
Maybe I did not express me clearly enough, I think that classes are
useful (and the language that I was speaking of, aldor, has them), but
it is not nice that the only way to have an overloaded function is to
define a type class, or that you need to fully implement a class just to
overload one function of it.
Vectors don't act like numbers, a vector space is not a field, even if
they have some common operations.
I find it misleading to define something a number when it does not
satisfy all the properties of numbers.
The numerical prelude might fix this, but still I think that class and
overloading should be distinct concepts.
More information about the Haskell-Cafe