jckarter/clay — Issue #102: Shorthand syntax for conversions in overloads
Author: jckarter
Created: 2011-12-31 03:17:35+00:00
State: open

A common boilerplate pattern is a pair of overloads, one that converts values to a canonical type and another that actually applies an algorithm to the canonical type:

```
foo(x, y) = foo(Int(x), String(y));

foo(x:Int, y:String) { ... }
```

It would be nice to have this built into the language. An idea KS and I came up with was to reuse the `as` keyword. The following definition:

```
foo(x as Int, y as String) { ... }
```

would be equivalent to the following two definitions:

```
foo(x, y) = forward ..foo(x as Int, y as String);

foo(x:Int, y:String) { ... }
```

The new `as` operator should be distinct from the constructor function, since operations like `int as Int` should be no-ops, and the implicit conversion operation should be limited to cheap and safe value-to-argument conversions in keeping with the "explicit is better than implicit" philosophy.