[Haskell-cafe] One-element tuple
Dan Burton
danburton.email at gmail.com
Fri Aug 16 05:04:14 CEST 2013
For the "consistency" you want, `data Oneple a = T a` is the best you can
do in Haskell.
T(CustId 47) is just one character off from what you actually want to
write: (Cust 47). And I presume you want the "extra bottom" that comes with
this, as opposed to just treating values as their own one-tuples.
I imagine you could write some fancy hack that uses the type system to
automatically promote values to Oneples of the given value when an
"expected: Oneple Foo, actual: Foo" error occurs. But this would not be
very useful in general.
An uglier option:
type Oneple a = (a, ())
-- Dan Burton
On Thu, Aug 15, 2013 at 7:05 PM, Ivan Lazar Miljenovic <
ivan.miljenovic at gmail.com> wrote:
> On 16 August 2013 11:35, 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
> >
> > (That is, it's annoying if you're trying to make typeclass instances for
> > extensible/contractable tuples. Yes, I know I could use HLists.)
> >
> > I'm not happy with either approach I've tried:
> >
> > data Oneple a = Oneple a -- (or newtype)
> > (Oneple $ CustId 47) -- too verbose
> >
> > type Oneple a = [a]
> > [CustId 47] -- at least looks bracket-y
> >
> > What do you do?
>
> http://hackage.haskell.org/package/OneTuple :p
>
> If you really wanted some form of parentheses you could possibly use
> quasiquoting for it...
>
> >
> > AntC
> >
> >
> >
> > _______________________________________________
> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130815/8ab47a8e/attachment.htm>
More information about the Haskell-Cafe
mailing list