Hacker News new | ask | show | jobs
by JoshTriplett 3321 days ago
You 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.
2 comments

Indeed, 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
Not 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?