是否可以为记录中的泛型类型声明 LinkedList 字段?



是否可以在教堂记录中为泛型类型声明 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

最新更新