3 ms·
> Haskell doesn't have any subtyping Num looks like something that's been subtyped.
by derleth 15y ago
> Haskell doesn't have any subtyping
Num looks like something that's been subtyped.
- nandemo 15y agoWell, it may look like but it isn't. Num is a typeclass, not a type. Like yummyfajitas said, typeclasses are similar to interfaces or abstract classes in Java, but they aren't the same. Consider Java's equals(). You can write 'a'.equals(foo) as long as foo is an Object. In contrast, look at Haskell's (==) function declared in Eq (I'm not giving an example using Num because Haskell provides some implicit conversions for numeric literals, which would introduce an unrelated complication in the example). (==) :: (Eq a) => a -> a -> Bool This functions accepts 2 arguments of any one type, as long that type is an instance of Eq. But we cannot use different types in the same call. That is, we can write ('a' == 'b') and ("foo" == "bar") but not ('a' = "foo"), because (==) is not defined for a Char and a String.