简体   繁体   English

这个Haskell定义是什么意思?

[英]What does this Haskell definition mean?

Eq a => [a] -> [(Int,a)]

我不知道Eq的含义或含义,所以我不知道整个定义的含义是什么?

That's a constraint about the type a used in the definition [a] -> [(Int,a)] : it says that it must define an instance for the Eq typeclass. 这是一个关于类型约束a在定义中使用[a] -> [(Int,a)] :它说,它必须定义一个实例的Eq类型类。 Basically, types with an Eq instance give support for equality and inequality operators, (==) and (/=) . 基本上,具有Eq实例的类型支持相等和不等式运算符(==)(/=)

More information about typeclasses here, at learnyouahaskell.com . 有关类型类的更多信息,请访问learnyouahaskell.com In nuce, typeclasses are somewhat similar to OOP's interfaces. 在nuce中,类型类似于OOP的接口。

这意味着[a]中的元素必须是Eq类型类,这意味着它们必须是可测试的相等。

The items of type a must be of Eq typeclass, as said before. 如前所述 ,类型a的项必须是Eq类型类。 The Eq typeclass defines types which can be compared for equality with other types, with th '==' operator/function Eq类型定义了可以与其他类型进行比较的类型,使用th'=='运算符/函数

This means that your function takes as its only parameter a list of 'a' items 这意味着您的函数将唯一参数作为“a”项列表

[a] is a list of types a

and returns a list of (Int, a) pairs, ie a list of 2-tuples where the first item in the tuple is an Int and the second is of same type as the list passed to the function. 并返回(Int,a)对的列表,即2元组的列表,其中元组中的第一项是Int,第二项与传递给函数的列表的类型相同。

(not native english speaker here, sorry :) ) (这里不是母语为英语的人,抱歉:))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM