[swift-evolution] Epic: Typesafe calculations

Brent Royal-Gordon brent at architechies.com
Thu Dec 24 06:45:21 CST 2015

> A first tiny step towards more safety would be empowering typealias and generate warnings when a function is used with the "wrong" parameter type ("Kelvin" requested, but plain Float given).
> Additionally, extensions written for a typealias shouldn't be treated like extensions for the underlying type.
> An extra benefit of this would be the possibility to have
> typealias Path = String
> and make a clean distinction between general String-methods and those that are only relevant for Strings that represent a Path in the file system — it would even be possible to generate failable initializers to document constraints of the "new" type.

There's been discussion of this before, actually. Search the archives for `newtype`, which is Haskell's version of this feature.

Brent Royal-Gordon

More information about the swift-evolution mailing list