Skip to content

Restrict syntax of typed patterns #11801

Closed
@liufengyun

Description

@liufengyun

In Scala 2, a typed pattern is always of the form x: T. Scala 3 changed the syntax to pat: T in #6919 to support syntax like 3956: BigInt.

This feature pat: T is potentially useful as argued by many. However, I'd like to argue that it's better to introduce it later:

As argued by C.A.R. Hoare in The Emperor's Old Clothes [1]:

When any new language design project is nearing completion, there is always a mad rush to get new features added before standardization. The rush is mad indeed, because it leads into a trap from which there is no escape. A feature which is omitted can always be added later, when its design and its implications are well understood. A feature which is included before it is fully understood can never be removed later.

While generalizing to pat: T from x: T might make specification simpler, it makes correct implementation more complex (bug #10994). To quote [1] again:

The price of reliability is the pursuit of the utmost simplicity.

Other context

References

  1. The Emperor's Old Clothes, C.A.R. Hoare, 1981

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions