4 ms·
Something as simple as "+" is already [a] a -> a -> a. Where did "a" come from? Whereas in e.g. Scala, "5 + 6" is just calling the "+" method on 5 (I can see it
by lmm 12y ago
Something as simple as "+" is already [a] a -> a -> a. Where did "a" come from? Whereas in e.g. Scala, "5 + 6" is just calling the "+" method on 5 (I can see it right there, on Int: "def +(x: Int): Int").
I also find OO polymorphism a bit more discoverable than typeclass-based polymorphism. You can look at an OO object in the REPL and see what methods it has on it, in a way that's harder to do in Haskell.
You pay the price eventually of course - in Scala you end up needing more machinery to be able to treat "+" as a two-argument function, and you need typeclasses for certain problems so you end up having two different forms of polymorphism. But the tradeoff is that you can learn the less general version first and get started quicker, even if you end up having to learn more overall.
- merijnv 12y ago> in e.g. Scala, "5 + 6" is just calling the "+" method on 5 What's calling? What's a method? What's 5 that lets me "call" "methods" on it? Yeah, absolutely nothing intimidating for a 10 year old there...
- lmm 12y ago> What's calling? What's a method? No different or harder than calling a function in Haskell. > What's 5 that lets me "call" "methods" on it? A value like any other. That's how you do everything in Scala - calling methods on values. Again, I don't see how you could reasonably claim this is any more intimidating or confusing than calling a function in Haskell. > Yeah, absolutely nothing intimidating for a 10 year old there... I didn't say that; just that it's less intimidating than Haskell. It doesn't introduce confusing abstraction immediately like Haskell does. In Scala, 5 is an Int, you can click through to what an Int is and see that it has a + method on it. "Hello" is a String, you can click through to what a String is and see that it has a startsWith method on it. In Haskell, "+" comes from a mysterious faraway place and you can see that it's "a :: Num => a -> a -> a". I do think this involves not just more symbols but genuinely more abstract concepts than the Scala version.