Hacker News new | ask | show | jobs
by bad_user 5101 days ago

     [Scala] Type inferencing, but not powerful type inference?
In Scala the Hindley–Milner type inferencing is not possible because Scala is OOP, compared to Haskell which isn't.

Ocaml does have Hindley-Milner, but not for the OOP features and whenever I played with Ocaml it felt like 2 different type-systems shoved into the same language (much like Obj-C). Scala on the other hand is more consistent, elegant and simpler. That's why it has "case classes", because case classes are used for algebraic data-types, which have special properties that aren't necessarily shared by normal classes.

And because of implicits, the type-system is also more powerful than what's available in Ocaml and even Haskell. It's arguably too powerful, but the things that the collections library can do have no match in other languages. E.g. http://stackoverflow.com/a/1728140/3280

I also liked to bitch and moan about the lack of real type inferencing in Scala, however in Ocaml and Haskell just because the types are not specified, that doesn't mean you can ignore those types. Quite the contrary, you always have to be aware of those types, as opposed to working in a dynamic language. That's why it's standard practice in Haskell to add those types explicitly for public APIs, because otherwise it hurts readability a lot.

1 comments

> And because of implicits, the type-system is also more powerful than what's available in Ocaml and even Haskell.

I don't think that's true. You do the same thing (e.g. collections that choose better representations) via type families/associated data types in Haskell. E.g. in [1] or [2]

That said, what is true is that Odersky has modified the Scala type system in quite interesting ways, specifically to support his collections library. [3]

[1]: http://hackage.haskell.org/package/adaptive-containers

[2]: http://hackage.haskell.org/package/accelerate

[3]: http://lampwww.epfl.ch/~odersky/papers/fsttcs09.html