在类型族实例上输入类约束
是否可以指定类型族的所有实例必须满足的类型类约束?
例如,如果给出以下声明,我将如何确保所有实例都是Eq
实例:
data family Channel c :: *
非常感谢,
迈克尔
这是你想要的?
{-# LANGUAGE FlexibleContexts, TypeFamilies, FlexibleInstances #-}
-- Data family inside a class so that we can add an extra Eq constraint
class Eq (Channel c) => MyClass c where
data Channel c :: *
-- A simple toy instance
instance MyClass Int where
data Channel Int = CI Int deriving Eq
-- A more complex instance with separate Eq instance
instance MyClass Char where
data Channel Char = CC Char
instance Eq (Channel Char) where
(CC x) == (CC y) = x == y
链接地址: http://www.djcxy.com/p/43137.html