Traits - (sort of) Multiple inheritance & (sort of) classic abstracts

199 views
Skip to first unread message

Alexander Kuzmenko

unread,
Jul 4, 2013, 6:09:13 PM7/4/13
to haxe...@googlegroups.com
Hello.
I've implemented traits with macros: https://github.com/RealyUniqueName/haxe-traits
This lib allows to reuse code without extending classes, brings (limited) multiple inheritance and several other use-cases.
Since it's almost 100% macro it is completely dependency-free.
Please, take a look and try :)
I would be grateful for any criticism and/or ideas about new features or use-cases.

Jason O'Neil

unread,
Jul 4, 2013, 7:35:42 PM7/4/13
to haxe...@googlegroups.com

Another very cool library... thanks Alex!

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

dlots

unread,
Jul 5, 2013, 1:42:46 AM7/5/13
to haxe...@googlegroups.com
https://github.com/back2dos/tinkerbell/issues/32

Check out my thoughts on the convenience of having interfaces automatically generated for the traits. Not possible with haxe macros at the moment but possible with caxe

Juraj Kirchheim

unread,
Jul 5, 2013, 3:55:08 AM7/5/13
to haxe...@googlegroups.com
As I have pointed out in that very thread, that convenience can be achieved by having traits being defined in interfaces instead of classes, which is what tink_lang does.


Alexander Kuzmenko

unread,
Jul 5, 2013, 4:07:30 AM7/5/13
to haxe...@googlegroups.com
Unfortunately i didn't know traits are already implemented in tinkerbell. I'll take a look.

Juraj Kirchheim

unread,
Jul 5, 2013, 4:14:05 AM7/5/13
to haxe...@googlegroups.com
As for criticism, we already have at least two libraries that do this:


My suggestion is to join at least some of these efforts, because there are relatively tricky things to get working:

1. Substitute type parameters (tink_lang in fact already does this);

    interface Foo<T> implements ITrait {
        function first(a:Iterable<T>):T return a.iterator.next();
    }
    class MyFoo implements Foo<Int> {}

2. Deal with imports (which haxe-traits does)
3. Deal with using and such:

    using Lambda;

    interface Foo implements ITrait {
        function bar(a:Iterable<String>) return a.has("foo");
    }
    class MyFoo implements Foo {}

To make this a really solid feature, where error messages don't make users panic, requires quite a bit of work.
Truth be told, after implementing it, I never really found it that useful to go the extra mile.

Regards,
Juraj

Alexander Kuzmenko

unread,
Jul 5, 2013, 4:29:12 AM7/5/13
to haxe...@googlegroups.com
Tinkerbell looks closer to what i am trying to achieve. I will try to contribute when i get back to traits.

пятница, 5 июля 2013 г., 12:14:05 UTC+4 пользователь back2dos написал:

Juraj Kirchheim

unread,
Jul 5, 2013, 4:32:02 AM7/5/13
to haxe...@googlegroups.com
On Fri, Jul 5, 2013 at 10:07 AM, Alexander Kuzmenko <al...@stablex.ru> wrote:
Unfortunately i didn't know traits are already implemented in tinkerbell. I'll take a look.

Well that's my fault of course. But because tink is quite big, it's important for me to only "officially release" stuff that is working well. Otherwise users get buried under hundreds of lines of error messages, none of which seem to explain the problem.

Juraj Kirchheim

unread,
Jul 5, 2013, 4:32:53 AM7/5/13
to haxe...@googlegroups.com
That would be very appreciated ;)


--

Simon Krajewski

unread,
Jul 5, 2013, 4:33:19 AM7/5/13
to haxe...@googlegroups.com
Am 05.07.2013 10:14, schrieb Juraj Kirchheim:
> As for criticism, we already have at least two libraries that do this:
>
> - https://github.com/andyli/puzzle
> - https://github.com/back2dos/tinkerbell
>
> My suggestion is to join at least some of these efforts, because there
> are relatively tricky things to get working:

I suppose it's somewhat frustrating to get this kind of reply to
presenting a new library, but I have to +1 what Juraj said. Some
collaboration would be great!

Simon

Cambiata

unread,
Jul 6, 2013, 2:24:41 AM7/6/13
to haxe...@googlegroups.com
There might be things to elaborate in the future, as pointed out in this thread... but

Thanx, Alexander, for another great release!

The first Haxe implementation of traits that I've been able to understand and use.
Very clear basic documentation and example and - very important for me and most users.
Great addition to the Haxe eco!

/ J

Alexander Kuzmenko

unread,
Jul 6, 2013, 3:22:43 AM7/6/13
to haxe...@googlegroups.com
I'm going to replace underlying code with tinkerbell based code for greater flexibility and expandability (though i'm not sure i will, because i got some wierd errors with tinkerbell yesterday), but API should stay the same.
There are problems in my traits implementations, which can be faced in case of intence use of traits. I hope i'll solve them as soon as i adopt my traits to tinkerbell :)

Laurence Taylor

unread,
Jul 6, 2013, 3:37:14 AM7/6/13
to haxe...@googlegroups.com
Out of curiosity, did you manage to get it to propagate type constraints properly? I was having a hell of a time with that last time I had a go.

regards,
Laurence

--

Juraj Kirchheim

unread,
Jul 6, 2013, 3:57:08 AM7/6/13
to haxe...@googlegroups.com
Could you give a short example of what you mean?

Regards,
Juraj

Juraj Kirchheim

unread,
Jul 6, 2013, 4:12:08 AM7/6/13
to haxe...@googlegroups.com
On Fri, Jul 5, 2013 at 10:33 AM, Simon Krajewski <si...@haxe.org> wrote:
I suppose it's somewhat frustrating to get this kind of reply to presenting a new library, but I have to +1 what Juraj said. Some collaboration would be great!

Yes, sorry. I see that it might sound quite harsh. To clarify: I am very happy to see more and more people getting into macros and building such advanced stuff. It's just that certain things (such as traits through Haxe macros) are so hard to get right, that collaboration is quite inevitable.

Regards,
Juraj

Justin Donaldson

unread,
Jul 6, 2013, 5:46:36 PM7/6/13
to Haxe

Also, if people are duplicating work unknowingly, it means that it is not easy to find libraries that provide the features they are interested in.  Not sure about a good solution there.

--

Alexander Kuzmenko

unread,
Jul 7, 2013, 3:08:32 AM7/7/13
to haxe...@googlegroups.com
Perhaps, it's my fault, i did no proper googling (but i did some :) ).
Maybe it's possible to somehow add haxe projects from github/bitbucket/etc to haxe.org search? Also it's libs maintainers responsibility to describe their libraries (and mention use-cases) as detailed as possible.

воскресенье, 7 июля 2013 г., 1:46:36 UTC+4 пользователь Justin Donaldson написал:
Reply all
Reply to author
Forward
0 new messages