Circling back one of the original examples that motivated this discussion, consider this data structure
def pomSettings: PomSettings = PomSettings(
description = "Hello",
organization = "com.lihaoyi",
url = "https://github.com/lihaoyi/example",
licenses = Seq(License.MIT),
versionControl = VersionControl.github("lihaoyi", "example"),
developers = Seq(Developer(id = "lihaoyi", name = "Li Haoyi", url = "https://github.com/lihaoyi"))
)
def pomSettings
already has a target type; we already know it is a PomSettings
object! Similarly, developers = Seq(Developer(...))
is redundant, and licenses = Seq(License.MIT)
is similarly redundant, both to humans (we know the english meaning of developers
) and also to the compiler (it knows developers
is of type Seq[Developer]
).
I would like to be able to say
def pomSettings: PomSettings = (
description = "Hello",
organization = "com.lihaoyi",
url = "https://github.com/lihaoyi/example",
licenses = [.MIT],
versionControl = .github("lihaoyi", "example"),
developers = [(id = "lihaoyi", name = "Li Haoyi", url "https://github.com/lihaoyi")]
)
To achieve this, we would need (a) collection literals (b) named-tuple-to-case-class implicit constructors and (c) some kind of enum-shorthand syntax for .MIT
and .github
.
Itâs a lot of new features, so I donât expect to be able to spec/discuss/implement/etc. all of them in the near future. But I think allowing Scala to concisely write this kind of common hierarchical data structure would be a nice ânorth starâ that we can slowly work towards, and maybe some day weâll even get there.