yon*_*ong 4 haskell type-kinds
我正在使用该linear库,我正在尝试创建一种推理三角矩阵的方法.
作为第一步,我正在尝试创建一种方法来计算下三角矩阵的大小.因此,例如,a M22具有带有3个元素的下三角矩阵,因此它将被映射到V3.
这是我的尝试:
import Linear
type family LowerTriPacked v :: * -> *
type instance LowerTriPacked V0 = V0
type instance LowerTriPacked V1 = V1
type instance LowerTriPacked V2 = V3
Run Code Online (Sandbox Code Playgroud)
但它没有打字检查,有:
Expecting one more argument to ‘V0’
The first argument of ‘LowerTriPacked’ should have kind ‘*’,
but ‘V0’ has kind ‘* -> *’
In the type ‘V0’
In the type instance declaration for ‘LowerTriPacked’
Run Code Online (Sandbox Code Playgroud)
这样做类型检查:
type family LowerTriPacked2 v :: *
type instance LowerTriPacked2 (V0 a) = V0 a
type instance LowerTriPacked2 (V1 a) = V1 a
type instance LowerTriPacked2 (V2 a) = V3 a
Run Code Online (Sandbox Code Playgroud)
但这不是我想要的,因为现在我无法使用
class (Traversable (LowerTriPacked2 v a)) => Triangular v a
Run Code Online (Sandbox Code Playgroud)
因为Traversable有种* -> *.
第一次尝试的语法出了什么问题?
Dan*_*ner 11
参数的默认类型是*; 但您可以通过提供类型注释来覆盖默认值.像这样:
type family LowerTriPacked (v :: * -> *) :: * -> *
Run Code Online (Sandbox Code Playgroud)