Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The best known typeclass implementation is that of Haskell

Oh, I don't know about that one. In Scala type-classes are interfaces and you can put that OOP to good use. For example in the Cats library, you get an Applicative type-class inheriting from Apply, a FlatMap inheriting from Apply and a Monad inheriting from FlatMap and Applicative. By comparison in Haskell a Monad is not automatically an Applicative and you get duplicate functions with different names, duplicate code, duplicate tests, etc.

Another advantage is that in Scala type-class instances are actual values that you can pass around. And because type-class instances are actual values, along with implicits which are lexically scoped, you can always provide another instance of a type-class, depending on context. You do not have the modularity problems arising from usage of type-classes in Haskell.

"The best implementation" is entirely subjective IMHO.

EDIT: got down-votes, not complaining, but I'd like to know where I'm mistaken. Thanks.



Didn't downvote, just FYI: Haskell's Applicative is a superclass of Monad now.


Which means you are now forced to write the boilerplate

pure = return

(<*>) = liftM2 ($)

In Scala, you get it for free for any monad.


Since GHC-7.10, the minimal complete definition for a Monad instance has been (>>=) (bind) only. So you can simply move the old definition for "return" into the Applicative instance as "pure" and you're good.


He means best-known, not best known. It's a statement about which is better known, not which is better.


Oh, sorry. I'm not a native English speaker, sometimes I have parsing issues :-)


i wouldn't sweat it, there's a fair amount of ambiguity in the english grammar D:




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: