GADT heads 中的类型变量有意义吗?
Are type variables in GADT heads meaningful?
这两个 GADT 声明之间有区别吗?
data A a b where
...
data A :: * -> * -> * where
...
没有区别。有人可能会认为,在 header 中不提及类型变量需要在构造函数签名中为它们使用不同的名称,如:
data A :: * -> * -> * where
AN :: Num x => x -> b -> A x b
AS :: IsString s => s -> b -> A s b
然而,正如the GHC Users Guide所说...
Unlike a Haskell-98-style data type declaration, the type variable(s) in the data Set a where
header have no scope.
... 所以这也有效:
data A a b where
AN :: Num x => x -> b -> A x b
AS :: IsString s => s -> b -> A s b
这两个 GADT 声明之间有区别吗?
data A a b where
...
data A :: * -> * -> * where
...
没有区别。有人可能会认为,在 header 中不提及类型变量需要在构造函数签名中为它们使用不同的名称,如:
data A :: * -> * -> * where
AN :: Num x => x -> b -> A x b
AS :: IsString s => s -> b -> A s b
然而,正如the GHC Users Guide所说...
Unlike a Haskell-98-style data type declaration, the type variable(s) in the
data Set a where
header have no scope.
... 所以这也有效:
data A a b where
AN :: Num x => x -> b -> A x b
AS :: IsString s => s -> b -> A s b