jckarter/clay — Issue #56: Can?, Monomorphic?, MonomorphicInputTypes primitives
Author: jckarter
Created: 2011-12-14 05:17:42+00:00
State: open
Labels: v0.1

`CallDefined?` is janky and doesn't deal with value kinds properly. A better primitive would be a SFINAE companion to `Type`, for which I like the name `Can?`:

```
[A, B | CallDefined?(add, A, B)] foo(a:A, b:B) = a + b;

[| Can?(a + b)] foo(a, b) = a + b;
```

To be useful, it would have to be possible for the predicate to refer to runtime argument names for type propagation purposes. However, it would be an error to actually evaluate a runtime argument.

`Can?` could also obviate the need for the gross `typeToLValue` and `typeToRValue` functions by accepting a monomorphic lambda, as in:

```
Sequence?(S) = Can?((s:S) -> iterator(s));
```

On a related note, it would also be useful to have `Monomorphic?` and `MonomorphicInputTypes` introspection for monomorphic lambdas and functions. These could be applied to allow things like the `CodePointer` constructor to infer the input and output types when applied to a monomorphic lambda or function:

```
CodePointer[[T, U, V], [W]]((t, u, v) -> w)

CodePointer((t:T, u:U, v:V) -> w)
```