Changeset b0fcd0e for doc/proposals


Ignore:
Timestamp:
Oct 2, 2024, 1:16:29 PM (12 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
1b770e40
Parents:
7968301
Message:

Tuple proposal spelling-grammar-typo fixes. No content changes intended.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/proposals/tuples.md

    r7968301 rb0fcd0e  
    33
    44This proposal is to update tuples, as they were created by Rob in his thesis,
    5 to address problems have appeared in their use since then. This proposal is
    6 an attempt to address some of those problems. Adding new functionality,
     5to address problems that have appeared in their use since then. This proposal
     6is an attempt to address some of those problems. Adding new functionality,
    77updating existing features and removing some problematic features.
    88
     
    5656
    5757Multi-Assignment assigns every element to the matching element of a source
    58 tuple (both tuples must be the same side).
     58tuple (both tuples must be the same size).
    5959
    6060        [int, long, float] dst;
     
    8888        }
    8989
    90 This is the unique feature of Cforall tuples. There are a few languages have
     90This is the unique feature of Cforall tuples. There are a few languages with
    9191multiple return values, but they are usually are a stand alone feature.
    9292
    9393### Tuple Casts
    9494
    95 C-style casts can be used on tuples. These usually conversion casts (casts
     95C-style casts can be used on tuples. These are usually conversion casts (casts
    9696that preform operations on the cast type, as opposed to reinterpreting the
    9797existing value).
     
    104104
    105105This casts the first element type from a char to an int and drops the last
    106 element. The second line can be replaced the following code, that creates
    107 a new tuple of by casting the kept elements of the old tuple:
     106element. The second line can be replaced with the following code, which creates
     107a new tuple by casting the kept elements of the old tuple:
    108108
    109109        [(int)x.0, (char)x.1];
     
    129129tuple is flattened, the second assertion "T max(Ts);" matches types with
    130130multiple parameters, although it is used as a tuple function inside the
    131 function body. For example, in three argument case (all three of the
     131function body. For example, in the three-argument case (all three of the
    132132same type), both assertions can match the same function. Then "Ts args"
    133 introduces args as a tuple, where it is past to max.
     133introduces args as a tuple, where it is passed to max.
    134134
    135135Issues with the Current State
    136136-----------------------------
    137 There are a veriaty of problems with the current implementation which we
     137There are a variety of problems with the current implementation which we
    138138would like to fix.
    139139
     
    141141
    142142Spoilers, this proposal actually takes them further away from being objects.
    143 But this illistrates why the current version is not as useful is it could be.
     143But this illustrates why the current version is not as useful is it could be.
    144144
    145145Tuples do not have the lifetime operators (copy construction, copy assignment
     
    150150This prevents tuples from being interwoven with regular polymorphic code.
    151151
    152 ### Providing TType Arguments is Inconistent
     152### Providing TType Arguments is Inconsistent
    153153
    154154The syntax for ttype arguments is slightly inconsistent. It hasn't come up
    155155much yet because you do not directly provide ttype polymorphic arguments to
    156 functions and the are very few existing use-cases for ttype structures.
    157 
    158 Passing arguments to a function inlines the arguments into inlines the
    159 arguments while passing them to a polymorphic type requires them to be
     156functions and there are very few existing use-cases for ttype structures.
     157
     158Passing arguments to a function inlines the arguments,
     159while passing them to a polymorphic type requires them to be
    160160enclosed in a tuple. Compare `function(x, y, z)` with `Type(A, [B, C])`.
    161161
     
    167167
    168168The tuple syntax conflicts with designators and the new attribute syntax.
    169 These conflicts break C compatability goals of Cforall. Designators have had
     169These conflicts break C compatibility goals of Cforall. Designators have had
    170170to their syntax change and Cforall cannot parse the new attributes.
    171171
    172172Although most of this redesign is about the semantics of tuples, but an
    173173update to tuple syntax that removes these conflicts that would improve the
    174 compatability of Cforall going forward (and also open up the new attribute
     174compatibility of Cforall going forward (and also open up the new attribute
    175175syntax for cforall features).
    176176
     
    183183The existing tuples will be even more "unstructured" than they are now.
    184184Tuples are considered a sequence of types or typed entities. These packs are
    185 then unpacked into the surounding context. Put differently, tuples are now
     185then unpacked into the surrounding context. Put differently, tuples are now
    186186flattened as much as possible, with some places (like parameter lists) being
    187187treated as an implicit tuple and the tuple being flattened into that.
    188188
    189 Structred tuples are now a separate feature, a structure called "tuple".
    190 These are polymorphic structures, an instance should act as a structure
    191 except that use indices instead of field names. These structures shouldn't
     189Structured tuples are now a separate feature, a structure called "tuple".
     190These are polymorphic structures; an instance should act as a structure,
     191except that it uses indices instead of field names. These structures shouldn't
    192192have to be used often, but fill in the use cases that unstructured tuples
    193193no longer support.
     
    197197Changed Features
    198198----------------
    199 Some of the concrete changes to the features of the languages.
     199Some of the concrete changes to the features of the language.
    200200
    201201### Structured Tuple Type
     
    261261
    262262These may not work exactly as given (for one, the copy assignment assertion
    263 in the first function would likely be redundent/conflicting with the implicit
     263in the first function would likely be redundant/conflicting with the implicit
    264264assertions on the parameters), but they show the pattern. Multi-assignment
    265 is also would be very hard to write with simple tuple types, because the
     265also would be very hard to write with simple tuple types, because the
    266266relationship between the two halves of the parameter list does have to line
    267267up, that cannot be enforced with two different tuples.
     
    272272polymorphic parameters as polymorphic type packs. The `Vars...` syntax
    273273introduces a pack of types into scope. It can be used in many of the same
    274 ways as a tuple tuple, but in some new ways to.
    275 
    276 The primary existing use remains, you can use a polymorphic pack in a
     274ways as a tuple, but in some new ways to.
     275
     276The primary existing use remains; you can use a polymorphic pack in a
    277277parameter list, both as part of an assertion and in the signature of the
    278 main function. The difference, is that this is not an enclosed tuple, but
     278main function. The difference is that this is not an enclosed tuple, but
    279279a series of types. The only effective difference this makes is it doesn't
    280280prefer to match another tuple/pack.
    281281
    282282This pattern continues to a parameter defined with a pack of types, which
    283 is considered a pack of parameters, and the name of it introduces is a pack
     283is considered a pack of parameters, and the name it introduces is a pack
    284284of variables, or a flattened tuple.
    285285
     
    287287        void function(Params values);
    288288
    289 New uses cases include declarations of members and variables. For example,
     289New use cases include declarations of members and variables. For example,
    290290the creation the structured tuple structure:
    291291
     
    296296
    297297This is again, treated as a pack of members. They have the same layout as
    298 if they were written out by hand. Now, the name get is still accessed is if
     298if they were written out by hand. Now, the name get is still accessed as if
    299299it was a regular, singular, member. The result of that expression is a
    300300pack expression, a tuple of all the field accesses, which can be used with a
     
    344344The unstructured tuple cannot represent all the types that the previous
    345345semi-structured tuple could. These cases still exist in various ways,
    346 special in the internals of a polymorphic type, but general should be
     346special in the internals of a polymorphic type, but in general should be
    347347considered in their reduced form.
    348348
     
    364364is to say a single type in an unstructured tuple is a no-op.
    365365
    366 Lastly, nested tuples are always flattened into to form a one deep tuple.
     366Lastly, nested tuples are always flattened into to form a one-deep tuple.
    367367This means that `[bool, [char, int], float]` is resolved as
    368368`[bool, char, int, float]`, with the internal structure of the tuple ignored.
     
    396396each element in the result tuple decided by the matching element of the
    397397range, which gives the index of the original tuple to place there.
    398 The type of the indices may be and intergal type, but all indices must be in
     398The type of the indices may be and integral type, but all indices must be in
    399399range, otherwise it is a compile time error.
    400400
     
    438438This would act much like a `FunctionDecl` except for tuples, narrowing the
    439439possible types, to `TupleType` instances instead of `FunctionType` instances,
    440 and storing some additonal information, in this case the names of the
     440and storing some additional information, in this case the names of the
    441441elements of the tuples.
    442442
     
    447447### Field Packs
    448448Field packs in structures will probably have to be written out in full by
    449 the specialization pass. If they are not it could have some negative effects
     449the specialization pass. If they are not, it could have some negative effects
    450450on layout, causing a structure to take up extra space. It may be able to
    451451reuse some of the specialization code for the existing tuples.
     
    469469tuple is a different polymorphic type.
    470470
    471 Tuple types and expressions are written with a parenthesized, comma seperated
     471Tuple types and expressions are written with a parenthesized, comma separated
    472472list of types or expressions. To avoid confusion with the grouping "(...)",
    473 one element tuples must have a trailing comma (and larger tuples may have a
     473one-element tuples must have a trailing comma (and larger tuples may have a
    474474trailing comma).
    475475
     
    479479
    480480Element access uses similar syntax to field access (that is "."), but uses an
    481 interger literal instead of a field name (for example: "pair.1"). Tuples
     481integer literal instead of a field name (for example: "pair.1"). Tuples
    482482support pattern matching with similar syntax to their expression form.
    483483
     
    495495meta-programming.
    496496
    497 C++ is also one of the few languages with support for varadic polymorphic
     497C++ is also one of the few languages with support for variadic polymorphic
    498498types, so there is one template that defines all the types. It is written
    499499as `std::tuple<TYPE...>`, where "TYPE..." is any number of comma separated
     
    501501
    502502There is no special syntax for member access of a tuple. You have to use a
    503 template function for example `std::get<0>( tuple )`.
     503template function, for example `std::get<0>( tuple )`.
    504504
    505505C++ also has structured binding, a kind of limited pattern matching. In a
     
    517517has functions for tuples of up to 7 elements.
    518518
    519 The syntax for tuples is a comma seperated list of elements. Either element
     519The syntax for tuples is a comma separated list of elements. Either element
    520520types to create a tuple type, or element values to create a tuple value. The
    521521context decides which one we are looking for. Such as `(6, "six")` or
     
    543543
    544544OCaml does not support 0 or 1 element tuples. It does however have the `unit`
    545 type which has one value written `()`.
     545type which has one value, written `()`.
    546546
    547547-   https://ocaml.org/docs/basic-data-types#tuples
    548548
    549549#### Swift
    550 Swift has tuple types that use the basic parenthesized list of comma
     550Swift has tuple types that use the basic parenthesized, comma
    551551separated list of types or values. It only supports 0 and 2 or more element
    552552tuples (the `Void` type is an alias for the empty tuple type).
     
    580580### Packs
    581581
    582 Packs (or unstructures tuples) are a much less common feature. In fact, there
     582Packs (or unstructured tuples) are a much less common feature. In fact, there
    583583might just be one language, C++, that supports packs. The most common use
    584584case for unstructured tuples is returning multiple values, so there is a
     
    604604
    605605#### Lua
    606 Lua is a scripting languague, is dynamically typed and stack based. Although
     606Lua is a scripting language, is dynamically typed and stack based. Although
    607607the stack usually only directly visible in the C-API, it does allow any
    608608function to return any number of values. Even in a single return, if the
     
    635635public:
    636636        template<typename... Args>
    637         Outer(Args&&... args) : inner(std::foward<Args>(args)...) {}
     637        Outer(Args&&... args) : inner(std::forward<Args>(args)...) {}
    638638};
    639639```
     
    641641In the first application, `Args&&... args` both uses a pack and introduces
    642642another one. `Arg0&& arg0, Arg1&& arg1, Arg2&& arg2, ...` is the pattern
    643 it explands too. The `&&` is used to copy the argument type's reference
     643it expands too. The `&&` is used to copy the argument type's reference
    644644qualifier (the default can strip references away).
    645645
    646646The second application, `std::forward<Args>(args)...` uses two packs. These
    647 are expanded in parellel, and must be the same length (in this case they
     647are expanded in parallel, and must be the same length (in this case they
    648648always will be). It also helps show that the `...` is actually the bit doing
    649649the expansion, it is a suffix "operator" to the expansion pattern.
     
    653653element of the `args` pack together.
    654654
    655 C++ about the best you could ask for in this area, but it does a lot of work
     655C++ is about the best you could ask for in this area, but it does a lot of work
    656656at compile time to make this happen.
    657657
Note: See TracChangeset for help on using the changeset viewer.