next up previous index
Next: Control structures Up: Basic data types and Previous: Options   Index


In pair.cecil:

The pair, triple, quadruple, and quintuple data structures can sometimes be useful, e.g., for returning a tuple of results from a function.

template object pair[T1,T2];
  extend type pair[`T1,`T2] subtypes pair[`S1 >= T1, `S2 >= T2];
  field first (@:pair[`T1,`T2]):T1;
  field second(@:pair[`T1,`T2]):T2;
  method pair(x:`T1, y:`T2):pair[T1,T2];
  method print_string(p@:pair[`T1,`T2]):string;
extend pair[`T1 <= comparable[T1], `T2 <= comparable[T2]]
        isa comparable[pair[T1,T2]];
  method =(p1@:pair[`T1 <= comparable[T1], `T2 <= comparable[T2]],
           p2@:pair[T1, T2]):bool;
extend pair[`T1 <= partially_ordered[T1], `T2 <= partially_ordered[T2]]
        isa partially_ordered[pair[T1,T2]];
  method <=(p1@:pair[`T1 <= partially_ordered[T1],
                     `T2 <= partially_ordered[T2]],
            p2@:pair[T1, T2]):bool;
  method <(p1@:pair[`T1 <= partially_ordered[T1],
                    `T2 <= partially_ordered[T2]],
           p2@:pair[T1, T2]):bool;
extend pair[`T1 <= hashable[T1], `T2 <= hashable[T2]]
        isa hashable[pair[T1,T2]];
  method hash(p@:pair[`T1 <= hashable[T1], `T2 <= hashable[T2]],
method <=_lex(q1@:pair[T1,T2], q2@:pair[T1,T2]):bool
                                        where ordered[`T1], ordered[`T2];
A pair is an immutable pair of arbitrary values. A pair of two types T1 and T2 is a subtype of pairs of any supertypes S1 and S2, e.g., a pair of an integer and a set is a subtype of a pair of a number and an unordered_collection. The pair method constructs a new pair. (The constructor methods for pairs, triples, quadruples, and quintuples do not start with new_ - like cons, they are exceptions from our naming convention for constructor methods.)

template object triple[T1,T2,T3];
  extend type triple[`T1,`T2,`T3]
        subtypes triple[`S1 >= T1, `S2 >= T2, `S3 >= T3];
  field signature first (triple[`T1,`T2,`T3]):T1;
  field signature second(triple[`T1,`T2,`T3]):T2;
  field third(@:triple[`T1,`T2,`T3]):T3;
  method triple(x:`T1, y:`T2, z:`T3):triple[T1,T2,T3];
  method print_string(p@:triple[`T1,`T2,`T3]):string;
extend triple[`T1 <= comparable[T1], `T2 <= comparable[T2],
              `T3 <= comparable[T3]]
        isa comparable[triple[T1,T2,T3]];
  method =(p1@:triple[`T1 <= comparable[T1],
                      `T2 <= comparable[T2],
                      `T3 <= comparable[T3]],
           p2@:triple[T1, T2, T3]):bool;
extend triple[`T1 <= partially_ordered[T1], `T2 <= partially_ordered[T2],
              `T3 <= partially_ordered[T3]]
        isa partially_ordered[triple[T1,T2,T3]];
  method <=(p1@:triple[`T1 <= partially_ordered[T1],
                       `T2 <= partially_ordered[T2],
                       `T3 <= partially_ordered[T3]],
            p2@:triple[T1, T2, T3]):bool;
extend triple[`T1 <= hashable[T1], `T2 <= hashable[T2], `T3 <= hashable[T3]]
        isa hashable[triple[T1,T2,T3]];
  method hash(p@:triple[`T1 <= hashable[T1],
                        `T2 <= hashable[T2],
                        `T3 <= hashable[T3]],
method <=_lex(q1@:triple[T1,T2,T3], q2@:triple[T1,T2,T3]):bool
                          where ordered[`T1], ordered[`T2], ordered[`T3];
Triples are an immutable triple of arbitrary values. A triple of three types T1, T2, and T3 is a subtype of triples of any supertypes S1, S2, and S3. The triple method constructs a new triple.

template object quadruple[T1,T2,T3,T4];
  extend type quadruple[`T1,`T2,`T3,`T4]
        subtypes quadruple[`S1 >= T1, `S2 >= T2, `S3 >= T3, `S4 >= T4];
  field signature first (quadruple[`T1,`T2,`T3,`T4]):T1;
  field signature second(quadruple[`T1,`T2,`T3,`T4]):T2;
  field signature third (quadruple[`T1,`T2,`T3,`T4]):T3;
  field fourth(@:quadruple[`T1,`T2,`T3,`T4]):T4;
  method quadruple(x:`T1, y:`T2, z:`T3, w:`T4):quadruple[T1,T2,T3,T4];
  method print_string(p@:quadruple[`T1,`T2,`T3,`T4]):string;
extend quadruple[`T1 <= comparable[T1], `T2 <= comparable[T2],
                 `T3 <= comparable[T3], `T4 <= comparable[T4]]
        isa comparable[quadruple[T1,T2,T3,T4]];
  method =(p1@:quadruple[`T1 <= comparable[T1],
                         `T2 <= comparable[T2],
                         `T3 <= comparable[T3],
                         `T4 <= comparable[T4]],
           p2@:quadruple[T1, T2, T3, T4]):bool;
extend quadruple[`T1 <= partially_ordered[T1], `T2 <= partially_ordered[T2],
                 `T3 <= partially_ordered[T3], `T4 <= partially_ordered[T4]]
        isa partially_ordered[quadruple[T1,T2,T3,T4]];
  method <=(p1@:quadruple[`T1 <= partially_ordered[T1],
                          `T2 <= partially_ordered[T2],
                          `T3 <= partially_ordered[T3],
                          `T4 <= partially_ordered[T4]],
            p2@:quadruple[T1, T2, T3, T4]):bool;
extend quadruple[`T1 <= hashable[T1], `T2 <= hashable[T2],
                 `T3 <= hashable[T3], `T4 <= hashable[T4]]
        isa hashable[quadruple[T1,T2,T3,T4]];
  method hash(p@:quadruple[`T1 <= hashable[T1], `T2 <= hashable[T2],
                           `T3 <= hashable[T3], `T4 <= hashable[T4]],
method <=_lex(q1@:quadruple[T1,T2,T3,T4], q2@:quadruple[T1,T2,T3,T4]):bool
          where ordered[`T1], ordered[`T2], ordered[`T3], ordered[`T4];
Quadruples are also provided.

template object quintuple[T1,T2,T3,T4,T5];
  extend type quintuple[`T1,`T2,`T3,`T4,`T5]
    subtypes quintuple[`S1 >= T1, `S2 >= T2, `S3 >= T3, `S4 >= T4, `S5 >= T5];
  field signature first (quintuple[`T1,`T2,`T3,`T4,`T5]):T1;
  field signature second(quintuple[`T1,`T2,`T3,`T4,`T5]):T2;
  field signature third (quintuple[`T1,`T2,`T3,`T4,`T5]):T3;
  field signature fourth(quintuple[`T1,`T2,`T3,`T4,`T5]):T4;
  field fifth(@:quintuple[`T1,`T2,`T3,`T4,`T5]):T5;
  method quintuple(x:`T1, y:`T2, z:`T3, w:`T4, v:`T5
  method print_string(p@:quintuple[`T1,`T2,`T3,`T4,`T5]):string;
extend quintuple[`T1 <= comparable[T1], `T2 <= comparable[T2],
                 `T3 <= comparable[T3], `T4 <= comparable[T4],
                 `T5 <= comparable[T5]]
        isa comparable[quintuple[T1,T2,T3,T4,T5]];
  method =(p1@:quintuple[`T1 <= comparable[T1],
                         `T2 <= comparable[T2],
                         `T3 <= comparable[T3],
                         `T4 <= comparable[T4],
                         `T5 <= comparable[T5]],
           p2@:quintuple[T1, T2, T3, T4, T5]):bool;
extend quintuple[`T1 <= partially_ordered[T1], `T2 <= partially_ordered[T2],
                 `T3 <= partially_ordered[T3], `T4 <= partially_ordered[T4],
                 `T5 <= partially_ordered[T5]]
        isa partially_ordered[quintuple[T1,T2,T3,T4,T5]];
  method <=(p1@:quintuple[`T1 <= partially_ordered[T1],
                          `T2 <= partially_ordered[T2],
                          `T3 <= partially_ordered[T3],
                          `T4 <= partially_ordered[T4],
                          `T5 <= partially_ordered[T5]],
            p2@:quintuple[T1, T2, T3, T4, T5]):bool;
extend quintuple[`T1 <= hashable[T1], `T2 <= hashable[T2],
                 `T3 <= hashable[T3], `T4 <= hashable[T4],
                 `T5 <= hashable[T5]]
        isa hashable[quintuple[T1,T2,T3,T4,T5]];
  method hash(p@:quintuple[`T1 <= hashable[T1], `T2 <= hashable[T2],
                           `T3 <= hashable[T3], `T4 <= hashable[T4],
                           `T5 <= hashable[T5]],
method <=_lex(q1@:quintuple[T1,T2,T3,T4,T5],
          where ordered[`T1], ordered[`T2], ordered[`T3], ordered[`T4],
Quintuples are also provided.

next up previous index
Next: Control structures Up: Basic data types and Previous: Options   Index

Cecil/Vortex Project