gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 10:18:51 25 4
gpt4 key购买 nike

是否可以在 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

关于chapel - 是否可以在记录中为泛型类型声明 LinkedList 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57680270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com