Haskell 单件捕获词典
在单例中捕获类型类约束的最佳方法是什么 例如,假设我有类型、种类和类Haskell 单件捕获词典,haskell,dependent-type,Haskell,Dependent Type,在单例中捕获类型类约束的最佳方法是什么 例如,假设我有类型、种类和类 singletons [d| data Names star = Names star |] class HasRepr a where repr :: proxy a -> String 在这里,我希望能够构造如下类型 type X = 'Names Int 找回他们的单身 singX :: Sing X singX = sing 然后把它分解成它的表象 reprX :: String re
singletons
[d|
data Names star = Names star
|]
class HasRepr a where
repr :: proxy a -> String
在这里,我希望能够构造如下类型
type X = 'Names Int
找回他们的单身
singX :: Sing X
singX = sing
然后把它分解成它的表象
reprX :: String
reprX (SNames sTy) = repr sTy
但是如果我推广这个,它会失败,错误如下
Could not deduce (HasRepr n2) arising from a use of ‘repr’
from the context ...
有没有一种方法可以让这个工作正常进行?你是说
reprX::Sing X->String
?是reprX::HasRepr t=>Sing('Names t)->String;reprX(SNames sTy)=repr sTy
对你的情况有好处吗?不是。一般来说,我不能公开需要约束的类型,我不认为它需要约束。我需要参数有一个约束,这样我就可以在下一步中使用它。也许我可以分析整个api
类型,以找到合适的/需要的约束-我很想这样做,但它看起来确实不雅观。