是否可以在记录中为通用类型声明LinkedList字段?

And*_*per 3 chapel

是否可以在Chapel记录中为通用类型声明LinkedList字段?

我想我要做的是:

  record LIST {
    var itm: LinkedList(?t);
  };
Run Code Online (Sandbox Code Playgroud)

?t声明记录时,链表元素的类型未知,但是:

./Structs.chpl:87: internal error: RES-CAL-NFO-0078 chpl version 1.19.0
Note: This source location is a guess.

Internal errors indicate a bug in the Chapel compiler ("It's us, not you"),
and we're sorry for the hassle.  We would appreciate your reporting this bug --
please see https://chapel-lang.org/bugs.html for instructions.  In the meantime,
the filename + line number above may be useful in working around the issue.
Run Code Online (Sandbox Code Playgroud)

非常感谢!

小智 6

为此,您可以使LIST类型通用。

record LIST {
  type T;
  var itm: LinkedList(T);
}

var lst: LIST(int);

writeln(lst.type:string);
writeln(lst.itm.type:string);
Run Code Online (Sandbox Code Playgroud)

产生...

LIST(int(64))
LinkedList(int(64))
Run Code Online (Sandbox Code Playgroud)

lst必须在声明时知道的所有字段的具体类型lst。我们使LIST记录对某个类型通用T,然后使用此类型信息实例化该字段itm

参见:https : //chapel-lang.org/docs/primers/genericClasses.html