问题描述
当我尝试派生实例时遇到此错误。
Cannot derive well-kinded instance of form ‘HFunctor (ControlFlowCMD ...)’
Class ‘HFunctor’ expects an argument of kind ‘(* -> *,*)
-> * -> *’
• In the newtype declaration for ‘ControlFlowCMD’
我正在尝试这样做:
newtype ControlFlowCMD fs a = ControlFlowCMD (ControlCMD fs a)
deriving HFunctor via (ControlCMD fs a)
您可以在第 278 行看到我的类型所基于的数据类型和实例并尝试派生 here。我不习惯使用派生方式 - 谁能解释一下这个错误的含义以及如何我会修复它吗?
解决方法
问题在于 string[,] data= new string[5,2] {{"F1","LINK1"},{"F1","LINK2"},{"F2","LINK3"},{"F3","LINK4"},"LINK5"}};
var items = Enumerable.Range(0,data.GetLength(0))
.Select(n => new {Key = data[n,0],Link = data[n,1]});
var query =
from i in items
group i by i.Key
into g
select new []
{
g.Key,string.Join(",",g.Select(x => x.Link))
};
var result = query.ToArray();
或等效的 (* -> *,*)
是种类级元组,必须启用 DataKinds
和 PolyKinds
扩展才能处理它. (我不完全确定为什么需要 (Type -> Type,Type)
;也许是为了允许更一般的类型推断。)
对于具有复杂种类的数据类型,通常需要 good idea 来启用 StandaloneKindSignatures
并明确给出种类签名:
PolyKinds