做出Maybe a的约束,其中Eq a [英] Making a constraint of Maybe a where Eq a
本文介绍了做出Maybe a的约束,其中Eq a的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何将Maybe限制为Eq a?它必须是*-> Constraint
How can I constrain to Maybe a where Eq a? It needs to be of kind * -> Constraint
我尝试过的事情:
class (a ~ Maybe b, Eq b) => K a where
instance (a ~ Maybe b, Eq b) => K a where
错误:
Not in scope: type variable ‘b’
示例用法:
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
有效的情况:
pp :: Test ((~) String) -> String
pp (Test o) = o ++ "X" -- GHC infers that o is a string
hh :: Test Eq -> Bool
hh (Test o) = o == o -- GHC infers that o is Eq
查看全文