The following code一類產生「預期的約束」錯誤:如何定義與一種類型的家庭
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ExistentialQuantification #-}
type family Note a
type instance Note String = String
data SomeNote = forall a. Note a => SomeNote a
class HasNote b where
noteOf :: b -> SomeNote
該錯誤是Expected a constraint, but 'Note a' has kind '*', in the definition of SomeNote
。爲什麼?我該如何解決它?
目標是在某些數據結構b中包含Note類型的實例,並使用noteOf b提取它,無論實例是什麼。