3 ms·
Classes are types. And in Scala, case classes are just an awkward take on algebraic data types. Scala doesn't even come close to Haskell. For one, it does not
by tikhonj 13y ago
Classes are types. And in Scala, case classes are just an awkward take on algebraic data types.
Scala doesn't even come close to Haskell. For one, it does not do anything to capture effects in the types. Apart from being markedly less safe, this also makes things like STM impractical. Additionally, implicits may be more powerful than typeclasses, but they're also easy to mess up: you lose canonicity. In Haskell, if you have a Set a, you know it uses the same ordering of a as any other Set a; in Scala, you lose this guarantee. You also don't have any notion of kinds, which makes quite a bit of otherwise-idiomatic code hard to write. Take a look at this post[1] for more examples and details.
[1]: http://www.reddit.com/r/haskell/comments/1pjjy5/odersky_the_trouble_with_types_strange_loop_2013/cd3bgcu http://www.reddit.com/r/haskell/comments/1pjjy5/odersky_the_...
If you want a simple yet powerful OO system, take a look at OCaml. It does OO much better than any other statically typed language I've used. The funny thing is, of course, that people don't use OCaml's object system--not because it's bad but because by the time you're using OCaml, you've already realized functional programming is the way to go. Most of the reasons I've heard for not using OCaml's object system apply even more to other OO languages!
OCaml's object types are expressive and, unlike Scala, fully inferable. And they don't mess variance up! You also get a dual sub-typing with polymorphic variants--I don't know if Scala can do anything comparable with case classes.
- runT1ME 13y ago>You also don't have any notion of kinds, which makes quite a bit of otherwise-idiomatic code hard to write. I'm not sure that is true. Otherwise this would not be possible: class MyExample[A[_]](a: A)
- tikhonj 13y agoYeah, I think that part was a bit inaccurate. The core problem is more like the fact that higher-kinded code is hard to write. You always end up writing in terms of concrete types--you can talk about A[_], but not about A by itself. This becomes a hassle when working with things like monad transformers.