Re: [Vala] valasemanticanalyzer error



On Fri, Aug 20, 2010 at 2:55 PM, Abderrahim KITOUNI <a kitouni gmail com> wrote:

shouldn't it be Iterable<G>?

Thanks, that got the basic proof of concept working. Now the issue is,
I want to write a generic map function whose output type should not
need to be encoded in the Enumerable type.

using Gee;

public interface Enumerable<G> : Iterable<G> {
  public delegate O DFunc<I, O>(I elem);

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

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

public string f(int i) {
  return "%d".printf(i);
}

public static int main(string[] args) {
  var a = new EnumerableList<int> ();
  a.add(1);
  a.add(2);
  a.add(3);
  var b = new Gee.ArrayList<string> ();
  a.map((Enumerable.DFunc<int, string>) f , b);
  foreach (string i in b) {
    stdout.printf("-- %s --\n", i);
  }

  return 0;
}


The strange bit is that the acc.add(fn(i)); line complains

test1.vala:8.7-8.9: error: missing generic type arguments
      acc.add(fn(i));
      ^^^

even though I'd expect acc to be well typed (I've declared it using

  var b = new Gee.ArrayList<string> ();

and should be able to use it via Gee.List, no?)

martin



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