Stephane Le Dorze a écrit :
> I really like to stretch the capabilities of Haxe language...
This discussion would be more appropriate on haXe list, but I'll answer
here :)
> I think that a very interesting extension of the inferencer would be
> typedef Union so that we could use the duck typing this way:
>
> class Peon {
> public function new() {
> }
> public function say () {
> }
> public function die () {
> }
> public function sleep () {
> }
> }
>
> typedef SayDie = { say : Void -> Void, die : Void -> Void }
> typedef Sleep = { sleep : Void -> Void }
>
> var l = new List<SayDie, Sleep>();
> l.add(peon);
You already have the following in haXe :
var s : SayDie = new Peon();
And :
var l = new List<Sleep>();
l.add(new Peon());
So there is already duck typing / type classes in haXe.
The only thing is that there is no syntax currently to composite two
typedefs together, but you can extend one with more definitions :
typedef SleepSayDie = {> SayDie, sleep : Void -> Void }
Nicolas
--
Neko : One VM to run them all
(http://nekovm.org)