Unit unboxed tuples

wren ng thornton wren at freegeek.org
Mon Jan 9 05:49:47 CET 2012


On 12/23/11 12:57 PM, Tyson Whitehead wrote:
> On December 23, 2011 09:37:04 Ganesh Sittampalam wrote:
>> On 23/12/2011 13:46, Ian Lynagh wrote:
>>> On Fri, Dec 23, 2011 at 01:34:49PM +0000, Simon Peyton-Jones wrote:
>>>> Arguments   Boxed      Unboxed
>>>> 3           ( , , )    (# , , #)
>>>> 2           ( , )      (# , #)
>>>> 1
>>>> 0           ()         (# #)
>>
>> It's worth mentioning that if you want to write code that's generic over
>> tuples in some way, the absence of a case for singletons is actually a
>> bit annoying - you end up adding something like a One constructor to
>> paper over the gap. But I can't think of any nice syntax for that case
>> either.
>
> I believe python uses (expr,) (i.e., nothing following the ,) to distinguish a
> singelton tupple from a braced term.  Not great, but possibly not that bad.
>
> The other option you could do is introduce another unambiguous brace symbol
> for tupples.  The new symbol would be optional except for the singelton.
>
> (- expr, expr, expr -)  =  (expr, expr, expr)
> (- expr, expr -)  =  (expr, expr)
> (- expr -)  =<unable to express>
> (- -)  =  ()

An alternative is to distinguish, say, (# x #) and its spaceful 
constructor (# #) from the spaceless (##); and analogously for the boxed 
tuples, though that introduces confusion about parentheses for boxing vs 
parentheses for grouping.

FWIW, I'd always thought that () disallowed intervening spaces, though 
ghci tells me that ain't so.

-- 
Live well,
~wren



More information about the Glasgow-haskell-users mailing list