我想表达一个Constraint
关于 kind 的类型k -> k -> Type
,用英语可以表述为:
一种类型
s
,使得, forallx
x'
,y
, andy'
whereCoercible x x'
andCoercible y y'
,Coercible (s x y) (s x' y')
或者用更简单的英语:
如果它的两个参数是可强制的,则该类型
s
始终是可强制的。
后者似乎已经非常接近haskell,而且我有一些看起来确实应该这样做的代码:
type Representational2 (s :: k -> k -> Type) =
forall x x' y y'. (Coercible x x', Coercible y y') => Coercible (s x y) (s x' y')
然而这不起作用,ghc 想Coercible (s x y) (s x' y')
成为一个类型,但它是一个Constraint
(ConstraintKinds
并且QuantifiedConstraints
在)。
• Expected a type, but
‘Coercible (s x y) (s x' y')’ has kind
‘Constraint’
• In the type ‘forall x x' y y'.
(Coercible x x', Coercible y y') => Coercible (s x y) (s x' y')’
In the type declaration for ‘Representational2’
我不完全理解发生了什么,但我认为 ghc 不喜欢 aConstraint
右侧的=>
存在type
。由于我可以使用 kind 创建类型别名,Constraint
并且可以使用 创建type
别名=>
,所以没问题。
问题是什么,我如何以它接受的方式向 ghc 表达这种约束?