fuuman
fuuman

Reputation: 461

Haskell - Map a ()

what does this line do?

Map a ()

I thought "map" is a function that works good with lists.

For example:

map (+1) [1,2,3] == [2,3,4]

But that is like

map :: (a->b) -> [a] -> [b] 
map f xs 

But what does

map a () 

mean? I mean, () is no list. Never seen this before.

Upvotes: 1

Views: 369

Answers (1)

Paul Manta
Paul Manta

Reputation: 31577

Map a () is a data type: it uses the class Data.Map to define a data structure that maps objects of type a to objects of type (). It is similar C++'s std::map, Java's HashMap, C#'s Dictionary, etc.

On the other hand, map is a function. If an identifier starts with a capital letter, that means it represents a type or a class, otherwise it represents a value or a function.

Edit: Type () is a 0-tuple (or an empty tuple). If you had type (a, b), that would be a 2-tuple because it can hold two elements; (a, b, c) would be a 3-tuple, etc. A 0-tuple is an "empty shell", it cannot hold any values. And in case you are wondering why a 0-tuple is useful, it is used mainly to indicate the absence of information.

Upvotes: 12

Related Questions