Funtions Using Type parameters with constraints.

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

Funtions Using Type parameters with constraints.

NekoHaxe
Hello Nicolas, list.

I'm trying to write some extern files for jQuery, and found a little problem.
Some of their functions like filter receive different types of parameters,
for example, filter can receive an expression that can be an string or
a function of type Int->Bool. function add can receive string, or
htmlDom or array<HtmlDom>. and so.

I tried to use type parameters wit constraints, but this doesn't work:

extern class JQuery implements ArrayAccess<HtmlDom>{
...
...
...
public function add<T:(String,HtmlDom,Array<HtmlDom>)>(expression:T):JQuery;
...
...
...
}

When trying to compile it throws an error:
"This notation is not allowed because it can't be checked"

As far as I know( according to the book) type parameters are allowed in functions
, but It says nothing of typed constraints, only for classes. Is there a reason
why this cannot work? I really don't want to use Dynamic for those parameters
if I can make them strongly typed.

Carlos




¡Todo sobre Amor y Sexo!
La guía completa para tu vida en Mujer de Hoy:
http://mx.mujer.yahoo.com/

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

Re: Funtions Using Type parameters with constraints.

NekoHaxe
"The type T must satisfy all listed constraints".

Duh, I should have read better, so type constraints are not what different
types are allowed, but what types T must be, all at once.
(Or I'm completely lost here...hehe)

Carlos

--- El lun 27-oct-08, NekoHaxe <[hidden email]> escribió:
De:: NekoHaxe <[hidden email]>
Asunto: Funtions Using Type parameters with constraints.
A: [hidden email]
Fecha: lunes, 27 octubre, 2008, 10:21 am

Hello Nicolas, list.

I'm trying to write some extern files for jQuery, and found a little problem.
Some of their functions like filter receive different types of parameters,
for example, filter can receive an expression that can be an string or
a function of type Int->Bool. function add can receive string, or
htmlDom or array<HtmlDom>. and so.

I tried to use type parameters wit constraints, but this doesn't work:

extern class JQuery implements ArrayAccess<HtmlDom>{
...
...
...
public function add<T:(String,HtmlDom,Array<HtmlDom>)>(expression:T):JQuery;
...
...
...
}

When trying to compile it throws an error:
"This notation is not allowed because it can't be checked"

As far as I know( according to the book) type parameters are allowed in functions
, but It says nothing of typed constraints, only for classes. Is there a reason
why this cannot work? I really don't want to use Dynamic for those parameters
if I can make them strongly typed.

Carlos




¡Todo sobre Amor y Sexo!
La guía completa para tu vida en Mujer de Hoy:
http://mx.mujer.yahoo.com/



¡Todo sobre Amor y Sexo!
La guía completa para tu vida en Mujer de Hoy:
http://mx.mujer.yahoo.com/

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

Re: Re: Funtions Using Type parameters with constraints.

Nicolas Cannasse
NekoHaxe a écrit :
> "The type T must satisfy all listed constraints".
>
> Duh, I should have read better, so type constraints are not what different
> types are allowed, but what types T must be, all at once.
> (Or I'm completely lost here...hehe)

Yes, that's right. Only Dynamic will work here.

Nicolas

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

Re: Re: Funtions Using Type parameters with constraints.

laurence taylor
Couldn't you do some hokey-pokey with an enum where each item is a class name, and then have the class typed as the enumerator. I don't know whether this would work the generator side, but it's only a few extra characters to do it manually. Consistency of API might be a barrier if you're porting though.

On Mon, Oct 27, 2008 at 5:42 PM, Nicolas Cannasse <[hidden email]> wrote:
NekoHaxe a écrit :

"The type T must satisfy all listed constraints".

Duh, I should have read better, so type constraints are not what different
types are allowed, but what types T must be, all at once.
(Or I'm completely lost here...hehe)

Yes, that's right. Only Dynamic will work here.

Nicolas

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


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