jckarter / clay

The Clay programming language
http://claylabs.com/clay
Other
403 stars 34 forks source link

'as' expression and argument conversions (fix issue #102) #461

Closed ghost closed 11 years ago

ghost commented 11 years ago

Implement 'as' expression: x as Int64 desugars too: alias overload asExpression(value, #T) = T(value); The type consructor overload is a quick default and should probably be changed.

'as' argument conversions:

[T when Integer?(T)]
overload foo(x:T as Int64, y as Float64) = T, x;

desugars too:

[T when Integer?(T)]
overload foo(forward x:T, forward y) = 
    forward ..foo(T, x as Int64, y as Float64);

[T]
overload foo(#T, x:Int64, y:Float64) = T, x;

Add couple of simple tests.

jckarter commented 11 years ago

This looks OK at a quick glance. Is there a reason you closed it?

stepancheg commented 11 years ago

I'm opposing the 'as expression' part (it provides little benefit, but complicates the language). 'as argument conversion' in parameter is nice.

ghost commented 11 years ago

I've closed this issue temporarily for a couple of reasons. Currently the 'as' desugars are done during loading, it works ok, but I'm going to try to desugar on demand. Also the commit history is a mess, i'll tidy this up a bit before reopening.

ghost commented 11 years ago

Tidied up the code/commits. I had a quick go at integrating the desugar into the match system without success. Seems to work fine as it is.

jckarter commented 11 years ago

Sounds good. In my thinking, the 'as' expression isn't as important as the sugar for conversions, since the alternatives are either excessive instantiation or the boilerplate of having to write two overloads.

ghost commented 11 years ago

Removed as as an expression/operator as it's not completely consistent with argument use.