News for hackers. Stuff that matters.
Re:Towards Scala 3 by bad_user on Friday April 20, 2018 @12:58PM (#16886458)
> 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.

Re:Towards Scala 3 by JD557 on Friday April 20, 2018 @01:16PM (#16886612)
I 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.

Re:Towards Scala 3 by lmm on Friday April 20, 2018 @03:06PM (#16887633)
I 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.
Re:Towards Scala 3 by ionforce on Friday April 20, 2018 @05:04PM (#16888426)
It's only surprising if you ascribe monadic properties to that syntax versus understanding it as literal syntactic sugar and absolutely nothing else.
Re:Towards Scala 3 by clhodapp on Friday April 20, 2018 @08:14PM (#16889279)
I 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/RE...)