4 ms·
> It's obvious that Scala was specifically designed to be a solid foundation on which one can implement the concepts of a little known branch of mathematics cal
by lmm 9y ago
> It's obvious that Scala was specifically designed to be a solid foundation on which one can implement the concepts of a little known branch of mathematics called the category theory, and almost every design choice in the language flows from there.
Nonsense. Scala was designed to make programming easier and safer than Java - XML literals and pattern matching certainly have nothing to do with category theory. Scala's for/yield has surprising behaviour when e.g. mixing lists and sets, precisely because it doesn't have a categorical grounding and was implemented in terms of what working programmers wanted to do with it rather than enforcing that you've formed a valid semigroupoid in the category of endofunctors.
Over time it's emerged that some categorical constructs provide useful ways of thinking about code and solving programming problems, but you're putting the cart before the horse if you think the language was designed for category theory.
- bad_user 9y ago> Scala's for/yield has surprising behaviour ... because it doesn't have a categorical grounding Not sure what you're talking about, but for/yield is syntactic sugar for map/flatMap, just like the "do notation" is in Haskell. Of course it has theoretical grounding, because it wouldn't work without flatMap being the monadic bind. > mixing lists and sets Again, not entirely sure what you're talking about, but if true, it's entirely unrelated to for/yield.
- JD557 9y agoI believe that he's referring to the fact that Scala's Set is not a monad, so it "shouldn't" have a .flatMap operation. Scala has other containers that have a .flatMap operation that are not real monads, such as Future and Try. That can lead to surprising behavior on for/yeld loops. Disclaimer: I do work in Scala and enjoy the language.
- lmm 9y agoI mean if you write something like: (for { x <- List(1, 1, 1) y <- Set(x) z <- List(y, y) } yield z).length the answer will be rather surprising, because in Scala for/yield is not necessarily monadic.
- ionforce 9y agoIt's only surprising if you ascribe monadic properties to that syntax versus understanding it as literal syntactic sugar and absolutely nothing else.
- clhodapp 9y agoI would say: it is `Set` and `List` that are wrong in that example, not `for`. That said, `for` really does have some issues (enter https://github.com/oleg-py/better-monadic-for/blob/master/README.md https://github.com/oleg-py/better-monadic-for/blob/master/RE...)