我怎样才能约束到Eq a?它需要是善良的 - >>约束
我尝试了什么:
class (a ~ Maybe b, Eq b) => K a where
instance (a ~ Maybe b, Eq b) => K a where
Run Code Online (Sandbox Code Playgroud)
错误:
Not in scope: type variable ‘b’
Run Code Online (Sandbox Code Playgroud)
用法示例:
data Test c = forall a. (c a) => Test a
r :: Test K -> Maybe Bool
r (Test o) = (==) <$> o <*> o -- I need GHC to infer that o is Maybe Eq
Run Code Online (Sandbox Code Playgroud)
有效的案例:
pp :: Test ((~) String) -> …
Run Code Online (Sandbox Code Playgroud) haskell ×1