在Haskell中,我可能会编写一个类型类(typeclass),并使用
type
声明来创建一个类型族(type family),代码如下:class ListLike k where
type Elem :: * -> *
fromList :: [Elem k] -> k
然后像这样编写实例:
instance ListLike [a] where
type Elem [a] = a
fromList = id
instance ListLike Bytestring where
type Elem Bytestring = Char
fromList = pack
我知道在 Idris 中可以创建类型类和类型级函数,但这些方法是针对给定类型的数据而非类型本身操作的。
我该如何像上面那样在 Idris 中创建一个受类型类限制的类型族?
Elem
写成一个函数。 - Random Dev