Typing optional rule idea.

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

Typing optional rule idea.

sledorze
Hi!

Recent improvements in type signature of JS APIs (thanks to overload) makes programming against JS native APIs feel more natural.
There's still some need on the completion side to propose all alternatives (perhaps it's on the trunk now, I've not checked it recently - windows nightlies are broken btw).

That's said, there's still room for improvements (as always) as settings parameters are often Dynamic.

I wonder if we cannot define some typedef with optional members so that one could define the settings parameters; type checking would catch non existing methods / vars and completion would help discovering those settings..

ex:
you define:

typedef Options = {
  var minHeight : Int;
  var ?maxHeight : Int; // Optional..
};

and a method:

function foo(opts : Options) {
...
}

then calling it with :
foo({ maxHeight : 50, minHeight : 5}); // Ok
foo({ minHeight : 5}); // Ok, maxHeight optional

foo({ maxHeight : 5}); // Fails, minHeight not defined
foo({ maxheight : 50, minHeight : 5}); // Fails; maxheight has a lower case 'h'

What do you think?

Stephane
Reply | Threaded
Open this post in threaded view
|

Re: Typing optional rule idea.

sledorze
Oh sorry; I meant

typedef Options = {
  minHeight : Int,
  ?maxHeight : Int // Optional..
};

(wow, must be tired)

Stéphane
Reply | Threaded
Open this post in threaded view
|

Re: Typing optional rule idea.

Heinz Hölzer-2
Your idea in other words ;)

http://haxe.org/com/features?lang=en

see optional structure fields.

best,
h

Am 30.09.2011 21:44, schrieb sledorze:

> Oh sorry; I meant
>
> typedef Options = {
>    minHeight : Int,
>    ?maxHeight : Int // Optional..
> };
>
> (wow, must be tired)
>
> Stéphane
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Typing-optional-rule-idea-tp6848922p6849066.html
> Sent from the Haxe mailing list archive at Nabble.com.
>


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

Re: Typing optional rule idea.

Cauê W.
well, about that, I've been thinking about making a macro for that and for having the facility of the anonymous structures for library parsing with the speed of strongly typed classes for the strongly typed targets.
It would be a first step for huge file formats, even though how haxe handles enums on the backend (array of dynamics) isn't also very ideal.

Anyway, what you're aiming for would be doable (I think) with macro autobuild and

@:structure(
{
someting:Int,
?optional:String
})
class PlaceHolder extends MyAutoBuildStructureClass {}

Of course that the native support for that would be fantastic!

-- On a side note, Nicolas, is there any way for you to support this so we can use with macros:
@:build(my.path.to.build())
class OtherBuildClass
{
var nonStaticVar:String = "oneExpressionHere";
}

Currently, even though the structure supports it, I get an error before being able to change it to a valid haxe expression with the build function

2011/9/30 Heinz Hölzer <[hidden email]>
Your idea in other words ;)

http://haxe.org/com/features?lang=en

see optional structure fields.

best,
h

Am <a href="tel:30.09.2011%2021" value="+553009201121" target="_blank">30.09.2011 21:44, schrieb sledorze:

Oh sorry; I meant

typedef Options = {
  minHeight : Int,
  ?maxHeight : Int // Optional..
};

(wow, must be tired)

Stéphane

--
View this message in context: http://haxe.1354130.n2.nabble.com/Typing-optional-rule-idea-tp6848922p6849066.html
Sent from the Haxe mailing list archive at Nabble.com.



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


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