函数 f 没有在以下代码中键入检查,它使用带有 Frames 和 Vinyl 的单例:
f :: forall rs1 rs2. SList rs1 -> Frame (Record rs1) -> Int
f (OnlyRecord s1 t1) df1 = broadcast (*) (rhead <$> df1)
pattern OnlyRecord :: Sing s -> Sing t -> SList '[s :-> t]
pattern OnlyRecord sym typsing = SCons (SRecArrow sym typsing) SNil
rhead :: Record ((s :-> t) ': sstt) -> t
rhead (x :& xs) = getCol $ getIdentity x
data instance Sing (a :: Type) where
SRecArrow :: Sing (s :: Symbol) -> Sing (t :: Type) -> Sing (s :-> t)
错误在于Couldn't match type ‘rs1’ with ‘'[s2 :-> t1]
对 rhead 的调用——基本上,模式匹配似乎没有像我预期的那样绑定 rs1 的结构。但是如果我内联模式,它会输入检查:
f' :: forall rs1 rs2. SList rs1 -> Frame (Record rs1) -> Int
f' (SCons (SRecArrow s1 t1) SNil) df1 = broadcast (*) (rhead <$> df1)
鉴于模式同义词应该是同义词,它不应该与内联模式相同吗?