是否可以在Chapel记录中为通用类型声明LinkedList字段?
我想我要做的是:
record LIST { var itm: LinkedList(?t); };
?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.
非常感谢!
为此,您可以使LIST
类型通用。
record LIST { type T; var itm: LinkedList(T); } var lst: LIST(int); writeln(lst.type:string); writeln(lst.itm.type:string);
产生...
LIST(int(64)) LinkedList(int(64))
lst
必须在声明时知道的所有字段的具体类型lst
。我们使LIST
记录对某个类型通用T
,然后使用此类型信息实例化该字段itm
。
参见:https : //chapel-lang.org/docs/primers/genericClasses.html