几个小时前,我构建了 GHC HEAD 来试验新的闪亮封闭类型系列。
{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances #-}
type family C a b where
C a [a] = [a]
C a a = [a]
现在我尝试C
使用:
class Combine a b where
combine :: a -> b -> C a b
instance Combine a [a] where
combine a b = a : b
instance Combine a a where
combine a b = [a, b]
导致此错误:
Couldn't match expected type ‛C a a’ with actual type ‛[a]’
...
In the expression: [a, b]
In an equation for ‛combine’: combine a b = [a, b]
In the instance declaration for ‛Combine a a’
在我看来,第二个等式与第一个等式不同(无论如何[a] a
都不能简化为),那么它为什么不编译呢?a a
a