Haskell在函数定义中使用Eq =>

Let*_*thi 0 haskell

我有一个包含抽象数据类型作为参数的函数.为了让我能够将我使用的这种抽象数据类型等同起来:

myfunction:: Eq x=> [x]->[x]->[x]
Run Code Online (Sandbox Code Playgroud)

所以它需要两个x列表,并输出一个[x]列表

但是,当我从另一个函数调用它时:

anotherfunction::[x] -> [x] -> [x]
anotherfunction a b = myfunction a b
Run Code Online (Sandbox Code Playgroud)

它说

在myfunction ab表达式中,没有因使用myfunction而产生的(Eq x)实例

但是,如果我从控制台调用myfunction,使用两个参数就可以了.

我该如何解决这个问题?

Aar*_*aid 10

使用Eq类型anotherfunction.

anotherfunction::Eq x => [x] -> [x] -> [x]
anotherfunction a b = myfunction a b
Run Code Online (Sandbox Code Playgroud)

myfunction仅适用于Eq类中的类型.但是您目前对anotherfunction声明的定义可以适用于任何类型.这将导致一个问题,如果你叫anotherfunction一个类型,它是不是Eq类-它不会是能够调用myfunction.