作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Haskell 的新手,所以我可能错过了一些明显的东西,但这里的问题似乎是什么?
单例库为 import Data.Singletons.TypeRepStar
中的 *
类型提供了一个 Sing
实例。
Sing
数据族定义如下..
data family Sing (a :: k)
并且 *
实例定义为..
data instance Sing (a :: *) where
STypeRep :: Typeable a => Sing a
我正在尝试使用以下内容重现此版本的最小版本...
{-# LANGUAGE GADTs
, TypeFamilies
, PolyKinds
#-}
module Main where
import Data.Typeable
data family Bloop (a :: k)
data instance Bloop (a :: *) where
Blop :: Typeable a => Bloop a
main :: IO ()
main = putStrLn "Hello, Haskell!"
但是我收到以下错误...
Main.hs:12:3: error:
• Data constructor ‘Blop’ returns type ‘Bloop a’
instead of an instance of its parent type ‘Bloop a’
• In the definition of data constructor ‘Blop’
In the data instance declaration for ‘Bloop’
|
12 | Blop :: Typeable a => Bloop a
| ^
最佳答案
编译器坚持认为 Bloop (a::*)
中的 a
和 Typeable a => Bloop 中的
与 a
aa
不同。如果将其中之一替换为 b
,它会产生完全相同的错误:
data instance Bloop (b :: *) where
Blop :: Typeable a => Bloop a
* Data constructor `Blop' returns type `Bloop a'
instead of an instance of its parent type `Bloop b'
* In the definition of data constructor `Blop'
In the data instance declaration for `Bloop'
可以使用 -fprint-explicit-kinds
使其更加明显:
* Data constructor `Blop' returns type `Bloop k a'
instead of an instance of its parent type `Bloop * a'
* In the definition of data constructor `Blop'
In the data instance declaration for `Bloop'
现在我们可以在错误消息中清楚地看到,一个 a
具有类型 k
,另一个具有类型 *
。由此看来,解决方案是显而易见的 - 显式声明第二个 a
的类型:
data instance Bloop (a :: *) where
Blop :: Typeable (a :: *) => Bloop (a :: *) -- Works now
出现这种情况的原因似乎是 PolyKinds
扩展。如果没有它,第二个 a
被假定为具有类型 *
,因此原始定义有效。
关于haskell - Singletons TypeRepStar Sing 数据实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45642783/
我是 Haskell 的新手,所以我可能错过了一些明显的东西,但这里的问题似乎是什么? 单例库为 import Data.Singletons.TypeRepStar 中的 * 类型提供了一个 Sin
我是一名优秀的程序员,十分优秀!