Hacker News new | ask | show | jobs
by anonymoushn 1329 days ago
What features of Scala allow the claimed things that are missing from other languages? Can you provide an example?
1 comments

It's the typeclasses that allow orphan instances.

For instance, let's say a library uses this interfaces:

    def doSomething[F[_]: Monad](param: F[Param]): F[Result] = ...
This allows to provide the effect on the callsite. This could simply by "Id (which means regulary executed code) or it could be async, an error type, something with logging or a combination of all those and more at the same type. The library doesn't know and doesn't care, it only constraints the interface if it needs to.
More precisely, since the concept of typeclasses is modeled in Scala using values, it is a bit more powerful and expressive (but also harder to use correctly) than for example Haskells counterpart.

And to add more: typeclasses are usually not enough here, you also need higher kinded types or the whole thing is useless for a lot of meaningful abstractions (such as dealing with errors or async code).