Haskell 刚性类型错误

Haskell 刚性类型错误,haskell,Haskell,我有以下代码: data Argument = Argument { ttype :: Type, value :: String } data Predicate = Predicate { lemma :: String , arguments :: [Argument] } class Throw a where throw :: a -> a -> Predicate instance Throw

我有以下代码:

data Argument  = Argument  { ttype :: Type, value :: String }
data Predicate = Predicate { lemma     :: String
                           , arguments :: [Argument] }

class Throw a where
    throw :: a -> a -> Predicate

instance Throw Argument where
    throw x y = Predicate { lemma = "throw", arguments = [x, y] }

qWho :: (Argument -> b -> Predicate) -> b -> [Argument]
qWho rel arg@(Argument x y) = STUFF HAPPENS HERE
qWho OTHER PATTERNS HAPPEN HERE
其思想是
qWho
签名中的
b
可以是
参数
谓词
(在第一种模式中,是
参数
),并将相应地采取行动。问题是,当我试图编译它时,我得到以下错误:

context.hs:162:11: error:
    • Couldn't match expected type ‘b’ with actual type ‘Argument’
      ‘b’ is a rigid type variable bound by
        the type signature for:
          qWho :: forall b. (Argument -> b -> Predicate) -> b -> [Argument]
        at context.hs:161:1-55
    • In the pattern: Argument x y
      In an equation for ‘qWho’:
          qWho rel (Argument x y)
            = STUFF I'M LEAVING OUT FOR BREVITY'S SAKE
    • Relevant bindings include
        rel :: Argument -> b -> Predicate (bound at context.hs:162:6)
        qWho :: (Argument -> b -> Predicate) -> b -> [Argument]
          (bound at context.hs:162:1)
知道我为什么会犯这个错误吗?另外,仅供参考,我是Haskell的新手,这是任务的一部分,所以虽然我不想让别人帮我完成任务,但我只是在寻找错误背后的原因。最后,以上所有代码(除了
qWho
)都是作为作业的一部分提供的,因此解决方案可能不应该是我必须更改该部分!:D


谢谢

多亏了@DanielWagner和@Alec才解决了这个问题

我没有尝试匹配模式,而是声明了两个class
Who
类型的实例(不确定这样说是否正确):

class Who b where
    qWho :: (Argument -> b -> Predicate) -> b -> [Argument]

instance Who Argument where
    qWho rel arg = ...

instance Who Predicate where
    qWho rel p = ...

我怀疑您误解了类型
(Argument->b->Predicate)->b->[Argument]
的含义。如前所述,
qWho
的调用者,而不是实现者,可以选择
b
。如果我决定调用
qWho
并给它一个
Argument->Int->Predicate
函数和一个
Int
,或者决定调用
qWho
并给它一个
Argument->(对于所有f.contractor f=>f Whoziwhatsit->Prepromorphism)->谓词和一个
对于所有f。反对者f=>f Whoziwhatsit->Prepromorphism
,作为
qWho
的实现者,您必须处理它。您确定
qWho
是正确的吗?就目前情况而言,仅仅是
qWho:(参数->b->谓词)->b->[参数]
qWho rel arg@(参数x y)=……
已经彼此不一致了。如果一个
b
没有约束,它不仅可以是
参数
谓词
——它可以是任何东西!此外,模式匹配的第一行表示
b
必须是
参数
(这也是错误消息告诉您的)。我正计划匹配更多模式。有一个
qWho rel pred@(谓词x y)=…
for
b
作为
谓词
和一个
qWho
来处理不正确的模式。这不能解决问题吗?哦,等等,我想我现在意识到了这个问题。我在做一些事情,比如声明一个函数
foo::b->Bool
,然后编写一组模式来匹配
b
可以是的特定事物,比如
foo1=。。。;foo'a'=。。。;foo等
。这是违法的。是吗?这更有意义。干得好