Here's a Scala 3 feature suggestion: I'd like to write for-comprehensions which know their generator type, like so: for[List] { x <- xs y <- ys } yield ... It would make it much easier to work out whether `xs` or `ys` is the wrong type.
-
Show this thread
-
Replying to @propensive
That could also give you a target for doing codegen on if's that appear before the first generator! And (if we are really going crazy), for zero-generator for comprehensions!
1 reply 0 retweets 1 like -
Replying to @clhodapp
You mean `for[F] yield x` would give `F.unit(x)`? I admire your ambition! And this syntax even looks nice!
1 reply 0 retweets 0 likes -
Replying to @propensive
Exactly. You could even do `for[F] { if x > 10 } yield 3`, which actually cleans up something that is currently kind of messy.
1 reply 0 retweets 1 like -
Replying to @clhodapp
The compiler would need to know how to construct the value without an existing value to work from, so it would need to infer the companion object from the TC, and call `unit` on it, which would need to be added to all the monad types.
1 reply 0 retweets 0 likes
I'm not sure how that would work for anything other than simple type constructors (a type lambda has no companion), but those probably would be the *useful* cases.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.