[Haskell-cafe] One-element tuple

AntC anthony_clayden at clear.net.nz
Mon Aug 19 11:40:57 CEST 2013


> Brent Yorgey <byorgey <at> seas.upenn.edu> writes:
> > 
> >     data Oneple a = Oneple a                   -- (or newtype)
> >     (Oneple $ CustId 47)                       -- too verbose
> > 
> 
> This is what the OneTuple package is for:
> 

Thank you Brent, and Ivan made the same suggestion.

Apart from being more verbose (2 extra chars) than the approach I disliked 
as being too verbose, does OneTuple have any merit?

> Dan Burton danburton.email at gmail.com 
> Fri Aug 16 03:04:14 UTC 2013 
claims that 
> "T(CustId 47) is just one character off from what you actually want ..."

(Bare T is very likely to be used already.)

But not only do I want to construct Oneples, I also want to pattern match 
and discriminate on their type in instances:

    f (T(CustId x)) = ...

    instance C (Oneple (CustId Int)) ...


I'm sensing there must be a need (since OneTuple is claimed to be a 
solution for it).

Would double-parens be too wild an idea?:

    ... ((CustId 47)) `extend` (CustName "Fred", Gender Male)

    f ((CustId x)) = ...

    instance C ((CustId Int)) ...

We'd have to avoid the double parens as in:

    ((meth obj) (double x))








More information about the Haskell-Cafe mailing list