Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Haskell doesn't have a single element tuple?

Tags:

haskell

I'm wondering why Haskell doesn't have a single element tuple. Is it just because nobody needed it so far, or any rational reasons? I found an interesting thread in a comment at the Real World Haskell's website http://book.realworldhaskell.org/read/types-and-functions.html#funcstypes.composite, and people guessed various reasons like:

  • No good syntax sugar.
  • It is useless.
  • You can think that a normal value like (1) is actually a single element tuple.

But does anyone know the reason except a guess?

like image 260
Takashi Yamamiya Avatar asked Feb 14 '11 21:02

Takashi Yamamiya


People also ask

Can you have a tuple with one element?

To create a tuple with only one item, you have add a comma after the item, otherwise Python will not recognize the variable as a tuple.

What is a tuple in Haskell?

A tuple is a fixed-length coupling of values, written in parentheses with the values separated by commas. One way to use this is to pass all parameters into a function as one value, rather than the curried functions we've seen so far.


1 Answers

There's a lib for that!

http://hackage.haskell.org/packages/archive/OneTuple/0.2.1/doc/html/Data-Tuple-OneTuple.html

Actually, we have a OneTuple we use all the time. It's called Identity, and is now used as the base of standard pure monads in the new mtl:

http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Data-Functor-Identity.html

And it has an important use! By virtue of providing a type constructor of kind * -> *, it can be made an instance (a trival one, granted, though not the most trivial) of Monad, Functor, etc., which lets us use it as a base for transformer stacks.

like image 78
sclv Avatar answered Sep 27 '22 20:09

sclv