Re: Gee Functional iterators



On Tue, Jul 13, 2010 at 7:48 PM, Maciej Piechotka <uzytkownik2 gmail com> wrote:
>
> Currently no. But the bug I posted is about adding this functionality to
> Vala. Currently Vala interfaces are more Java/C#-like.

Okay, I was trying some experiments to understand where the bug comes
in. This works, for instance:

$ cat mix.vala
public interface Hello {
  public void say_hello() {
    stdout.printf("hello");
  }
}

public class Testing : GLib.Object, Hello {

}

public static int main(string[] args){
  Testing a = new Testing();
  a.say_hello();
  return 0;
}

But this does not:

using Gee;

public interface Enumerable<G> : Iterable {

  public delegate G DType(G elem);

  public void map(DType fn, Gee.List<G> acc) {
    foreach (G i in this) {
      acc.add(fn(i));
    }
  }
}

public class EnumerableList<G> : Gee.ArrayList<G>, Enumerable<G> {
}

public static int main(string[] args) {
  var a = new EnumerableList<string> ();
  a.add("1");
  a.add("2");
  a.add("3");
  var b = new Gee.ArrayList<string> ();
  a.map( (i) => { return i; }, b);  // dies for want of g_dup_func
  foreach (string i in b) {
    stdout.printf("%s", i);
  }

  return 0;
}

And the problem seems to be that generics and delegates mix poorly
(that is, we could possibly workaround
https://bugzilla.gnome.org/show_bug.cgi?id=546305 if we only had
proper support for delegates with generic input and return types). Is
that correct? I'm still getting to grips with the way vala does
generics.

martin


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]