Opened 10 years ago

Closed 4 years ago

#1245 closed feature request (wontfix)

Turn tuples into syntactic sugar for heterogeneous lists

Reported by: benja.fallenstein@… Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.6
Keywords: Cc: pho@…, merehap@…, gtener@…, p.balzarek@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


It would be nice if (x,y,z) were syntactic sugar for a heterogeneous list, i.e. (x :*: y :*: z :*: HNil) where

data a :*: b = a :*: b
data HNil = HNil

(:*: associating to the right). Using functional dependencies and the techniques from the HList paper, we could then process tuples of arbitrary length in a uniform matter: for example, the Data.Monoid.Monoid instances for tuples. At the same time, this would create a slightly more light-weight syntax for heterogeneous lists, making them more acceptable for use cases like functions with optional or keyword arguments.

I'm not sure how much existing code would this would break. Showing and reading heterogeneous lists as tuples doesn't seem hard to implement. I don't know about Typeable and friends.

Change History (11)

comment:1 Changed 10 years ago by igloo

Milestone: _|_

This sounds pretty blue-sky to me, but I don't know enough about hlists to comment properly.

comment:2 Changed 9 years ago by PHO

Cc: pho@… added

comment:3 Changed 8 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:4 Changed 8 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:5 Changed 7 years ago by merehap

Cc: merehap@… added
Type of failure: None/Unknown

comment:6 Changed 6 years ago by vivian

Or maybe make tuples rebindable syntax. I don't like the idea of wielding heterogenous lists everywhere, someone might get hurt.

comment:7 Changed 6 years ago by agocorona

I also want some kind of syntactic sugar for H. Lists.

The absence of syntactic sugar makes heterogeneous list to look scary. People in haskell is accostumed to syntactic sugaring, so people think of not sugared expressions as second class.

I´ don't know the details, but it seems that tuples are in the language to cover the heterogeneous flexibility thing that homogeneous lists may not provide, but they introduce its own inflexibilities; These repeating instances for two, three, four and so on tuples makes them artificial and repetitive. In its comparison, a complex but unique H. List instance look elegant. specially if it is sugarized.

An alternative to sugarize H.Lists preserving tuples could be to use {} to sugarize H. lists as


and desugarize it into:

x :*: y :*: z :*: {}

Just like [] means empty list, {} would mean HNil, the empty heterogeneous list.

But this alternative , if implemented, would soon render tuples obsolete. These () (,) constrctors may create marginally faster and compact structures, but they are much less manageable.

comment:8 Changed 6 years ago by tener

Cc: gtener@… added

I second the idea by agocorona.

comment:9 Changed 6 years ago by Philonous

Cc: p.balzarek@… added

comment:10 Changed 4 years ago by morabbin

Wouldn't agocorona's proposal clash with layout braces?

comment:11 Changed 4 years ago by simonmar

Resolution: wontfix
Status: newclosed

I don't think this ticket is serving a useful purpose, if people are interested in the feature then it needs to be discussed and fleshed out thoroughly on the wiki.

Note: See TracTickets for help on using tickets.