简体   繁体   English

GHC存在量化单例

[英]GHC existentially quantified singleton

I'm using GHC 7.10 and the singletons package. 我正在使用GHC 7.10和singletons包。 There's a GADT named SomeSing in this library that allows you to existentially quantify a singleton. 这个程式库中有一个名为SomeSing的GADT ,可让您实质上量化单身人士。 It's definition looks like this: 它的定义如下所示:

data SomeSing (kproxy :: KProxy k) where
  SomeSing :: Sing (a :: k) -> SomeSing ('KProxy :: KProxy k)

And it works great. 而且效果很好。 We can wrap up a singleton with this so that only the kind is known, not the type. 我们可以用它包装一个单例,以便只知道类型,而不知道类型。

I wanted to create a variant, a similar wrapper that would allow me to wrap up a singleton and the result of a type function applied to it: 我想创建一个变体,一个类似的包装器,使我可以包装一个单例并将类型函数的结果应用于它:

data SomeSingWith (kproxy :: KProxy k) (f :: TyFun k n -> *) where
  SomeSingWith :: Sing (a :: k) -> Apply g a -> SomeSingWith ('KProxy :: KProxy k) g

However, I get this error: 但是,我收到此错误:

Data constructor ‘SomeSingWith’ cannot be GADT-like in its *kind* arguments
  SomeSingWith :: forall (k :: BOX) (g :: TyFun k * -> *) (a :: k).
                  Sing a -> Apply g a -> SomeSingWith 'KProxy g
In the definition of data constructor ‘SomeSingWith’
In the data declaration for ‘SomeSingWith’

What does this mean? 这是什么意思? And can it be fixed, or is what I'm doing impossible in GHC? 可以解决这个问题吗,或者我在GHC中做不到的事情吗?

I figured it out. 我想到了。 The second argument of TyFun needs to be kinded * instead of being allowed to be any arbitrary kind. TyFun的第二个参数需要为*而不是任意类型。 This makes sense. 这是有道理的。 However, the error message associated with the mistake is not helpful. 但是,与错误相关的错误消息没有帮助。

data SomeSingWith (kproxy :: KProxy k) (f :: TyFun k * -> *) where
  SomeSingWith :: Sing (a :: k) -> Apply g a -> SomeSingWith ('KProxy :: KProxy k) g

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM