Math.min, Math.max automatique typing ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Math.min, Math.max automatique typing ?

Blue Sans douze
Hello list !

I have a simple question : Can't Math.min, Math.max & co being automatically typed using macro system ?
Let me explain myself.

var total:Int = 0;
total = Math.min(total, 50);

It is obvious for anyone that the result will be an Int. Not for the compiler, it throws a compile error, so I have to do :

total = Std.int(Math.min(total, 50));

It makes my code harder to read. So I'm just asking : Can't Math.min return an Int if the type of the two parameters is Int ?
Maybe it could be a sort of Math.min<T>(a:T, b:T);
I don't know much thing about type parameter or macros ^^'.

Thanks.
Blue112.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Math.min, Math.max automatique typing ?

Nicolas Cannasse
Le 28/07/2011 08:18, Blue Sans douze a écrit :

> Hello list !
>
> I have a simple question : Can't Math.min, Math.max & co being
> automatically typed using macro system ?
> Let me explain myself.
>
> var total:Int = 0;
> total = Math.min(total, 50);
>
> It is obvious for anyone that the result will be an Int. Not for the
> compiler, it throws a compile error, so I have to do :
>
> total = Std.int(Math.min(total, 50));
>
> It makes my code harder to read. So I'm just asking : Can't Math.min
> return an Int if the type of the two parameters is Int ?
> Maybe it could be a sort of Math.min<T>(a:T, b:T);

It could be done with a macro, but I don't want to introduce macros
doing not-standard-typing in the standard library right now.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Math.min, Math.max automatique typing ?

laurence taylor
Couldn't it also be done with using?

On Thu, Jul 28, 2011 at 12:44 PM, Nicolas Cannasse <[hidden email]> wrote:
Le 28/07/2011 08:18, Blue Sans douze a écrit :

Hello list !

I have a simple question : Can't Math.min, Math.max & co being
automatically typed using macro system ?
Let me explain myself.

var total:Int = 0;
total = Math.min(total, 50);

It is obvious for anyone that the result will be an Int. Not for the
compiler, it throws a compile error, so I have to do :

total = Std.int(Math.min(total, 50));

It makes my code harder to read. So I'm just asking : Can't Math.min
return an Int if the type of the two parameters is Int ?
Maybe it could be a sort of Math.min<T>(a:T, b:T);

It could be done with a macro, but I don't want to introduce macros doing not-standard-typing in the standard library right now.

Nicolas

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Math.min, Math.max automatique typing ?

Heinz Hölzer-2
In reply to this post by Nicolas Cannasse
By the way, do you plan to integrate function type parameter constraints
in the nearer future ;)


Am 28.07.2011 12:44, schrieb Nicolas Cannasse:

> Le 28/07/2011 08:18, Blue Sans douze a écrit :
>> Hello list !
>>
>> I have a simple question : Can't Math.min, Math.max & co being
>> automatically typed using macro system ?
>> Let me explain myself.
>>
>> var total:Int = 0;
>> total = Math.min(total, 50);
>>
>> It is obvious for anyone that the result will be an Int. Not for the
>> compiler, it throws a compile error, so I have to do :
>>
>> total = Std.int(Math.min(total, 50));
>>
>> It makes my code harder to read. So I'm just asking : Can't Math.min
>> return an Int if the type of the two parameters is Int ?
>> Maybe it could be a sort of Math.min<T>(a:T, b:T);
>
> It could be done with a macro, but I don't want to introduce macros
> doing not-standard-typing in the standard library right now.
>
> Nicolas
>


--
haXe - an open source web programming language
http://haxe.org