[m-users.] Tuples as defined by the Book

Fabrice Nicol fabrnicol at gmail.com
Tue Feb 22 09:32:54 AEDT 2022


Hi everyone,

I confess to being a bit befuddled at the somewhat terse and elusive 
definition given by the reference manual on Type types (3.1.2.2):

    "The tuple types are {}, {T}, {T1, T2}, . . .
    A tuple type is equivalent to a discriminated union type (see
    Section 3.2.1 [Discriminated
    unions], page 33) with declaration
         :- type {Arg1, Arg2, ..., ArgN}
             --->     { {Arg1, Arg2, ..., ArgN} }."

The equivalence with discriminated union types is clear; the type 
declaration is a bit less so.

My understanding of tuples would rather be as follows:

    :- type {Arg1, Arg2, ..., ArgN}
         --->     {} (Arg1, Arg2, ..., ArgN).

In other words, tuple terms look to me as (instantiated) discriminated 
union types with anonymous constructors '{}' of arity N consisting of 
the two joined tokens '{' and '}'.

This is evidenced among others by tests/hard_coded/tuple_test.m:30.

I think the reference manual could perhaps rephrase its explanation in a 
more convincing and clear-cut way as above.

I honestly do not understand the manual definition; to  me it 
irresistibly smacks of infinite recursion. Something vaguely Chomskian 
in me, against all odds, keeps rewriting this declaration as follows:

     :- type {Arg1, Arg2, ..., ArgN}
         --->     { { { Arg1, Arg2, ..., ArgN} } }.

     :- type {Arg1, Arg2, ..., ArgN}
         --->     { { { { Arg1, Arg2, ..., ArgN} } } }.

     :- type {Arg1, Arg2, ..., ArgN}
         --->     { { { { { Arg1, Arg2, ..., ArgN} } } } }.

(... to Infinity ...)

somewhat hellishly.

But there must be something I missed there; I would be grateful for any 
principled denial of these misconceptions of mine (while we are all 
still alive).

Fabrice
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20220221/882a890f/attachment.html>


More information about the users mailing list