3 ms·
One advantage of significant whitespace is that it may enable a very concise (G)ADT notation: enum Tree[T] Branch(t: Tree[T]) Leaf(t: T) Compa
by virtualwhys 9y ago
One advantage of significant whitespace is that it may enable a very concise (G)ADT notation:
enum Tree[T]
Branch(t: Tree[T])
Leaf(t: T)
Compare that with preset day Scala:
sealed trait Tree[T]
case class Branch(t: Tree[T]) extends Tree[T]
case class Leaf(t: T) extends Tree[T]
In general with this proposal the `case` keyword could be implied in any pattern matching block. That alone would be a big win wrt to reducing keyword noise, something the MLs have enjoyed for decades.
- JoshTriplett 9y agoYou wouldn't need significant whitespace to do this; any block syntax would work. The following, for instance, would still drastically reduce the noise: enum Tree[T] { Branch(t: Tree[T]) Leaf(t: T) } The main benefit here involves using a block instead of "extends", and using "enum" instead of the odd use of a class hierarchy.
- virtualwhys 9y agoNot sure, all of the proposed syntax changes in Dotty require `case` in pattern matching blocks. With braces how would you parse this (contrived) example? foo match { x: Bar => (y: Int) => x.num + y x: Baz => ... } With significant whitespace the first block of indented code would mark a `case` pattern, with subsequent indents belonging to the matched pattern. With braces I suspect the `case`less version becomes more difficult to parse. Otherwise why require `case` in pattern matches?
- rbonvall 9y agoIndeed, there is already a proposal for an enum syntax in dotty that looks almost exactly like that: enum Tree[T] { case Branch(t: Tree[T]) case Leaf(t: T) } https://github.com/lampepfl/dotty/issues/1970 https://github.com/lampepfl/dotty/issues/1970