user1351008
user1351008

Reputation: 63

What does this Haskell definition mean?

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

I don't know what the Eq means or does so I don't know what the whole definition means?

Upvotes: 3

Views: 294

Answers (3)

lud
lud

Reputation: 2001

The items of type a must be of Eq typeclass, as said before. The Eq typeclass defines types which can be compared for equality with other types, with th '==' operator/function

This means that your function takes as its only parameter a list of 'a' items

[a] is a list of types a

and returns a list of (Int, a) pairs, i.e 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.

(not native english speaker here, sorry :) )

Upvotes: 1

Sven Hager
Sven Hager

Reputation: 3194

This means that the elements in [a] must be of the Eq typeclass, which means that they must be testable for equality.

Upvotes: 5

Riccardo T.
Riccardo T.

Reputation: 8937

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. Basically, types with an Eq instance give support for equality and inequality operators, (==) and (/=).

More information about typeclasses here, at learnyouahaskell.com. In nuce, typeclasses are somewhat similar to OOP's interfaces.

Upvotes: 10

Related Questions