部分应用的等式约束 [英] Partially applied equality constraint
问题描述
class(a〜b)=>等于b
实例(a〜b)=>等于ab
可以说我以后有一个数据类型:
data D(c :: * - > Constraint)其中
D :: Proxy c - > D c
然后像这样有效:
D(Proxy ::(Proxy(Equal Int)))
我的问题是,有没有办法写 当我将 类/实例hack看起来很糟糕,但至少可以工作,但是还有其他可能更干净的方法实现这个吗? 注意我在实际的代码中使用比平等更复杂的约束,我只是认为这将是一个很好的例子。 b $ b 您根本不需要类,您可以在 GHC 8.0.1有一个错误,有时会导致崩溃,但它只是一个错误,它在8.0.2中修复。您所描述的类/实例组合对于此错误确实是一种有效的解决方法。 如果您不需要向后兼容8.0.1,则可以使用 Consider the following: Lets say I later have a data type: Then something like this is valid: My question is, is there any way to write It seems that when I define The class/instance hack looks bad but at least it works, but is there any other maybe cleaner way of achieving this? Note I'll be using constraints more complex than equality in my actual code, I just thought this would be a good example. You do not need a class at all, you can just use There is a bug in GHC 8.0.1 which sometimes makes it crash, but it is just a bug, and it's fixed in 8.0.2. The class / instance combo you're describing is indeed an effective workaround for this bug. If you do not need backwards compatibility with 8.0.1, you can use 这篇关于部分应用的等式约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
Equal
定义为类型族 Equal Int
不起作用,因为它是一个不完整的应用程序。
(〜)
中使用前缀符号。
(〜)Int
或代理服务器((〜)Int)
直接。class (a ~ b) => Equal a b
instance (a ~ b) => Equal a b
data D (c :: * -> Constraint) where
D :: Proxy c -> D c
D (Proxy :: (Proxy (Equal Int)))
Equal
other than the repetitive class/instance notation I've used? Equal
as a type family Equal Int
doesn't work because it's an incomplete application.(~)
in prefix notation.(~) Int
or Proxy ((~) Int)
directly.