[Haskell-cafe] One-element tuple
Chris Wong
chrisyco+haskell-cafe at gmail.com
Tue Aug 20 07:56:34 CEST 2013
> It seems to me that this is Identity given a different name.
Close. But Identity is declared using newtype (just like monad
transformers), whereas OneTuple is declared with data (like the other
tuples).
This may or may not matter, depending on your use case.
>
> On 20/08/2013 1:17 PM, "Ivan Lazar Miljenovic" <ivan.miljenovic at gmail.com>
> wrote:
>>
>> On 20 August 2013 11:07, AntC <anthony_clayden at clear.net.nz> wrote:
>> >> Daniel F <difrumin <at> gmail.com> writes:
>> >>
>> >> Can you please elaborate why this inconsistency is annoying and what's
>> > the use of OneTuple?
>> >> Genuine question,
>> >
>> > Hi Daniel, the main annoyance is the verbosity (of using a data type and
>> > constructor), and that it no longer looks like a tuple.
>> >
>> > The inconsistency is because a one-element tuple is just as cromulent as
>> > a
>> > n-element, or a zero-element. (And that a one-element tuple is a
>> > distinct
>> > type from the element on its own/un-tupled.)
>>
>> Why is it as "cromulent" (especially as I'm not so sure we could
>> really consider () to be merely a zero-element tuple)?
>>
>> I can see what you're trying to do here, but for general usage isn't a
>> single element tuple isomorphic to just that element (which is what
>> newtypes are for if you need that distinction)?
>>
>> >
>> > So if I have instances (as I do) like:
>> >
>> > instance C (a, b) ...
>> > instance C () ...
>> >
>> > I can't usefully put either of these next two, because they're equiv to
>> > the third:
>> >
>> > instance C (( a )) ...
>> > instance C ( a ) ...
>> > instance C a ... -- overlaps every instance
>> >
>> > Similarly for patterns and expressions, the so-called superfluous parens
>> > are just stripped away, so equivalent to the bare term.
>> >
>> > The use of OneTuple is that it comes with all Prelude instances pre-
>> > declared (just like all other tuple constructors). I don't see that it
>> > has
>> > an advantage over declaring your own data type(?) I'd also be interested
>> > to know who is using it, and why.
>>
>> As far as I'm aware, it's just a joke package, but two packages
>> dealing with tuples seem to use it:
>> http://packdeps.haskellers.com/reverse/OneTuple
>>
>> >
>> > What I'm doing is building Type-Indexed Tuples [1] mentioned in HList
>> > [2],
>> > as an approach to extensible records [3], on the model of Trex [4] --
>> > all
>> > of which acknowledge one-element records/rows/tuples. And then I'm using
>> > the tuples as a platform for relational algebra [5] with natural Join
>> > (and
>> > ideas from Tropashko's 'Relational Lattice' [6]).
>> >
>> > Is there anybody using OneTuple 'in anger'?
>> >
>> > AntC
>> >
>> > [1] M. Shields and E.Meijer. Type-indexed rows. In Proceedings
>> > of the 28th ACM SIGPLAN-SIGACT symposium on Principles
>> > of Programming Languages, pages 261–275. ACMPress, 2001.
>> > [2] http://hackage.haskell.org/package/HList
>> > [3] http://www.haskell.org/haskellwiki/Extensible_record
>> > [4] http://web.cecs.pdx.edu/~mpj/pubs/polyrec.html
>> > [5] http://en.wikipedia.org/wiki/Relational_algebra#Natural_join_
>> > [6] http://vadimtropashko.wordpress.com/relational-lattice/
>> >
>> >>
>> >>
>> >>
>> >> On Fri, Aug 16, 2013 at 5:35 AM, AntC <anthony_clayden <at>
>> > clear.net.nz> wrote:
>> >> There's an annoying inconsistency:
>> >> (CustId 47, CustName "Fred", Gender Male) -- threeple
>> >> (CustId 47, CustName "Fred) -- twople
>> >> -- (CustId 47) -- oneple not!
>> >> () -- nople
>> >
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > 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
>> http://IvanMiljenovic.wordpress.com
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
--
Chris Wong, fixpoint conjurer
e: lambda.fairy at gmail.com
w: http://lfairy.github.io/
More information about the Haskell-Cafe
mailing list