[Haskell-cafe] Records vs Tuples

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Tue Jan 14 05:27:35 UTC 2014

On 14 January 2014 14:58, Cary Cherng <ccherng at gmail.com> wrote:
> What exactly is the purpose in having both records and tuples? They
> seem to behave rather similarly although records do have the extra
> naming of the fields that tuples don't.

Tuples: let you quickly group values together for one-off cases.

Custom data types: named grouping of values so you can give them a
specific type; optionally not exposing constructor so that you can
hide internals.  Record syntax is a a way of naming specific fields
within these data types.

Note that what you actually seem to be asking is "why have any data
type whose constructor can take more than one value", as this is what
a tuple is a specific instance of:

data Pair a b = Pair a b

data Triple a b c = Triple a b c


You can consider tuples to be pre-defined types with convenient
syntax.  But if you want to properly type your code you should define
your own types as appropriate.

> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list