Very new to Haskell, but I was just mulling this over; when I first learned about typeclasses, I saw the apparent benefit of being able to assert that a parameter to a function belongs to two typeclasses instead of just one. Ie, in Java, for example, you can ensure that a parameter to a function belongs to a particular interface by doing something like:<div>

<br></div><div>int doSomething(Comparable c) { ... }</div><div><br></div><div>But there&#39;s no real way of ensuring an argument implements two interfaces, whereas in Haskell you can make sure that an argument belongs to two (or however many) typeclasses.</div>

<div><br></div><div>doSomething :: (Ord a, Eq a, OtherTypeClass a) =&gt; a -&gt; Int</div><div>...</div><div><br></div><div>But as I thought about this, I couldn&#39;t seem to think of a practical case where this would be useful. The basic typeclasses in Haskell seem to follow a hierarchy. Ie, anything that belongs to Ord belongs to Eq, anything that belongs to Enum belongs to Ord, anything that belongs to Num belongs to Enum. I suppose there may be certain cases involving Functors where there would be a point to specifying multiple typeclasses (eg, an Int would not work with (Functor a, Ord a)), but I guess I&#39;m still somewhat skeptical about how often such a check would be necessary in practical applications.</div>

<div><br></div><div>So I guess I&#39;m just wondering if someone could give me an example of a practical case of the typeclass system allowing you to do a check like this that would not have been possible with interfaces. Or is there another benefit to typeclasses over interfaces that I&#39;ve missed?</div>

<meta http-equiv="content-type" content="text/html; charset=utf-8">