2 ms·
I don't get your argument. What's the difference between module Numeric def even? # ... end end and even? :: (Numeric t) -> a
by derefr 15y ago
I don't get your argument. What's the difference between
module Numeric
def even?
# ...
end
end
and
even? :: (Numeric t) -> a
Both declare functions that consume something implementing the Numeric type/protocol, and return something else. I don't see the practical difference between them, other than the calling syntax of the result.
- Locke1689 15y agoFirst, the even function is only defined for integers, not general numeric types. Second, type classes are not objects. Ad hoc polymorphism is used to denote different actions for different types but it doesn't break typing. The type integer is not the type object-integer: even? :: Integer -> Bool I am actually thoroughly confused where you got your type specification. Were you trying to say: class Integral a where even? :: a -> Bool even? :: (Integral a) => a -> Bool The reason why this disturbs me is because I find it difficult to draw the line at why even? should be even? :: (Integral a) => a -> Bool instead of even? :: Integer -> Bool. This doesn't make sense -- it's not a good use for typeclasses. There aren't many different categories of types which have a semantic notion of being even but a different implementation or type restriction. Even is just... even. It's just an operation on the integers. There's no need to bring ad hoc polymorphism in here.