No matching definitions.

tur/tuple

stdlib/tuple.tur

typed N-ary tuples (Tuple2..Tuple8).

Fixed-arity heterogeneous tuples with statically typed elements. Phase TP1 shipped Tuple2 only; Phase TP2 extends the kind ladder (KIND_ARROW3..KIND_ARROW5); Phase TP3 removes the arity cap entirely (Kind is now uint16_t) and ships Tuple6..Tuple8.

Tuple2 is intentionally distinct from Pair[A B]; see the "two-tuple-types problem" decision in docs/tuple-type-plan.md.

Surface sugar: in type-annotation position, a bracket list [T1 T2 ... Tn] is shorthand for (TupleN T1 T2 ... Tn) (2 <= N <= 8), mirroring the value-level tuple destructure (let [[a b] e] ...). For example : [int cstr] means : (Tuple2 int cstr) and nests recursively ([int [cstr int]] -> (Tuple2 int (Tuple2 cstr int))). The lowering lives in src/compiler/elab_types.c.

Language gap: tuple3..tuple8 and their per-N accessors are mechanical, copy-paste expansions of the Tuple2 pattern -- there is no variadic-generic way to write "a tuple of N typed elements" in one definition. The eventual fix is a primitive variadic tuple kind; the trade-offs are tracked in docs/archive/tuple-variadic-type-plan.md (Option B, deferred) and docs/design/tuple-variadic-vs-hlist.md. Until one of those ships, the arity ladder below is maintained by hand.

Since: Phase TP1 (Tuple2); Phase TP2 (Tuple3..Tuple5); Phase TP3 (Tuple6..Tuple8)

defstruct

Tuple2

(defstruct Tuple2 [A B] (e1 A) (e2 B))

two-element tuple with element types A, B.

Since: Phase TP1

defn

tuple2

(tuple2 [A B])

construct a Tuple2[A B].

afirst element (type A)
bsecond element (type B)

A Tuple2[A B] value.

(tuple2 1 "hi")  ; => Tuple2(1, "hi")

Since: Phase TP1

defn

tuple2-1st

(tuple2-1st [A B])

first element of a Tuple2[A B].

tTuple2[A B]

The first element of type A.

(tuple2-1st (tuple2 10 20))  ; => 10

Since: Phase TP1

defn

tuple2-2nd

(tuple2-2nd [A B])

second element of a Tuple2[A B].

tTuple2[A B]

The second element of type B.

(tuple2-2nd (tuple2 10 20))  ; => 20

Since: Phase TP1

defstruct

Tuple3

(defstruct Tuple3 [A B C] (e1 A) (e2 B) (e3 C))

three-element tuple with element types A, B, C.

Since: Phase TP2

defn

tuple3

(tuple3 [A B C])

construct a Tuple3[A B C].

afirst element (type A)
bsecond element (type B)
cthird element (type C)

A Tuple3[A B C] value.

(tuple3 1 "hi" 3.14)  ; => Tuple3(1, "hi", 3.14)

Since: Phase TP2

defn

tuple3-1st

(tuple3-1st [A B C])

first element of a Tuple3[A B C].

Since: Phase TP2

defn

tuple3-2nd

(tuple3-2nd [A B C])

second element of a Tuple3[A B C].

Since: Phase TP2

defn

tuple3-3rd

(tuple3-3rd [A B C])

third element of a Tuple3[A B C].

Since: Phase TP2

defstruct

Tuple4

(defstruct Tuple4 [A B C D] (e1 A) (e2 B) (e3 C) (e4 D))

four-element tuple with element types A, B, C, D.

Since: Phase TP2

defn

tuple4

(tuple4 [A B C D])

construct a Tuple4[A B C D].

afirst element (type A)
bsecond element (type B)
cthird element (type C)
dfourth element (type D)

A Tuple4[A B C D] value.

(tuple4 1 "hi" 3.14 #t)  ; => Tuple4(1, "hi", 3.14, #t)

Since: Phase TP2

defn

tuple4-1st

(tuple4-1st [A B C D])

first element of a Tuple4[A B C D].

Since: Phase TP2

defn

tuple4-2nd

(tuple4-2nd [A B C D])

second element of a Tuple4[A B C D].

Since: Phase TP2

defn

tuple4-3rd

(tuple4-3rd [A B C D])

third element of a Tuple4[A B C D].

Since: Phase TP2

defn

tuple4-4th

(tuple4-4th [A B C D])

fourth element of a Tuple4[A B C D].

Since: Phase TP2

defstruct

Tuple5

(defstruct Tuple5 [A B C D E] (e1 A) (e2 B) (e3 C) (e4 D) (e5 E))

five-element tuple with element types A, B, C, D, E.

Since: Phase TP2

defn

tuple5

(tuple5 [A B C D E])

construct a Tuple5[A B C D E].

afirst element (type A)
bsecond element (type B)
cthird element (type C)
dfourth element (type D)
efifth element (type E)

A Tuple5[A B C D E] value.

(tuple5 1 "hi" 3.14 #t :ok)  ; => Tuple5(1, "hi", 3.14, #t, :ok)

Since: Phase TP2

defn

tuple5-1st

(tuple5-1st [A B C D E])

first element of a Tuple5[A B C D E].

Since: Phase TP2

defn

tuple5-2nd

(tuple5-2nd [A B C D E])

second element of a Tuple5[A B C D E].

Since: Phase TP2

defn

tuple5-3rd

(tuple5-3rd [A B C D E])

third element of a Tuple5[A B C D E].

Since: Phase TP2

defn

tuple5-4th

(tuple5-4th [A B C D E])

fourth element of a Tuple5[A B C D E].

Since: Phase TP2

defn

tuple5-5th

(tuple5-5th [A B C D E])

fifth element of a Tuple5[A B C D E].

Since: Phase TP2

defstruct

Tuple6

(defstruct Tuple6 [A B C D E F] (e1 A) (e2 B) (e3 C) (e4 D) (e5 E) (e6 F))

six-element tuple with element types A, B, C, D, E, F.

Since: Phase TP3

defn

tuple6

(tuple6 [A B C D E F])

construct a Tuple6[A B C D E F].

afirst element (type A)
bsecond element (type B)
cthird element (type C)
dfourth element (type D)
efifth element (type E)
fsixth element (type F)

A Tuple6[A B C D E F] value.

(tuple6 1 "hi" 3.14 #t :ok 99)  ; => Tuple6(1, "hi", 3.14, #t, :ok, 99)

Since: Phase TP3

defn

tuple6-1st

(tuple6-1st [A B C D E F])

first element of a Tuple6[A B C D E F].

Since: Phase TP3

defn

tuple6-2nd

(tuple6-2nd [A B C D E F])

second element of a Tuple6[A B C D E F].

Since: Phase TP3

defn

tuple6-3rd

(tuple6-3rd [A B C D E F])

third element of a Tuple6[A B C D E F].

Since: Phase TP3

defn

tuple6-4th

(tuple6-4th [A B C D E F])

fourth element of a Tuple6[A B C D E F].

Since: Phase TP3

defn

tuple6-5th

(tuple6-5th [A B C D E F])

fifth element of a Tuple6[A B C D E F].

Since: Phase TP3

defn

tuple6-6th

(tuple6-6th [A B C D E F])

sixth element of a Tuple6[A B C D E F].

Since: Phase TP3

defstruct

Tuple7

(defstruct Tuple7 [])

seven-element tuple with element types A, B, C, D, E, F, G.

Since: Phase TP3

defn

tuple7

(tuple7 [A B C D E F G])

construct a Tuple7[A B C D E F G].

afirst element (type A)
bsecond element (type B)
cthird element (type C)
dfourth element (type D)
efifth element (type E)
fsixth element (type F)
gseventh element (type G)

A Tuple7[A B C D E F G] value.

(tuple7 1 2 3 4 5 6 7)  ; => Tuple7(1, 2, 3, 4, 5, 6, 7)

Since: Phase TP3

defn

tuple7-1st

(tuple7-1st [A B C D E F G])

first element of a Tuple7[A B C D E F G].

Since: Phase TP3

defn

tuple7-2nd

(tuple7-2nd [A B C D E F G])

second element of a Tuple7[A B C D E F G].

Since: Phase TP3

defn

tuple7-3rd

(tuple7-3rd [A B C D E F G])

third element of a Tuple7[A B C D E F G].

Since: Phase TP3

defn

tuple7-4th

(tuple7-4th [A B C D E F G])

fourth element of a Tuple7[A B C D E F G].

Since: Phase TP3

defn

tuple7-5th

(tuple7-5th [A B C D E F G])

fifth element of a Tuple7[A B C D E F G].

Since: Phase TP3

defn

tuple7-6th

(tuple7-6th [A B C D E F G])

sixth element of a Tuple7[A B C D E F G].

Since: Phase TP3

defn

tuple7-7th

(tuple7-7th [A B C D E F G])

seventh element of a Tuple7[A B C D E F G].

Since: Phase TP3

defstruct

Tuple8

(defstruct Tuple8 [])

eight-element tuple with element types A, B, C, D, E, F, G, H.

Since: Phase TP3

defn

tuple8

(tuple8 [A B C D E F G H])

construct a Tuple8[A B C D E F G H].

afirst element (type A)
bsecond element (type B)
cthird element (type C)
dfourth element (type D)
efifth element (type E)
fsixth element (type F)
gseventh element (type G)
heighth element (type H)

A Tuple8[A B C D E F G H] value.

(tuple8 1 2 3 4 5 6 7 8)  ; => Tuple8(1, 2, 3, 4, 5, 6, 7, 8)

Since: Phase TP3

defn

tuple8-1st

(tuple8-1st [A B C D E F G H])

first element of a Tuple8[A B C D E F G H].

Since: Phase TP3

defn

tuple8-2nd

(tuple8-2nd [A B C D E F G H])

second element of a Tuple8[A B C D E F G H].

Since: Phase TP3

defn

tuple8-3rd

(tuple8-3rd [A B C D E F G H])

third element of a Tuple8[A B C D E F G H].

Since: Phase TP3

defn

tuple8-4th

(tuple8-4th [A B C D E F G H])

fourth element of a Tuple8[A B C D E F G H].

Since: Phase TP3

defn

tuple8-5th

(tuple8-5th [A B C D E F G H])

fifth element of a Tuple8[A B C D E F G H].

Since: Phase TP3

defn

tuple8-6th

(tuple8-6th [A B C D E F G H])

sixth element of a Tuple8[A B C D E F G H].

Since: Phase TP3

defn

tuple8-7th

(tuple8-7th [A B C D E F G H])

seventh element of a Tuple8[A B C D E F G H].

Since: Phase TP3

defn

tuple8-8th

(tuple8-8th [A B C D E F G H])

eighth element of a Tuple8[A B C D E F G H].

Since: Phase TP3

defmacro

tuple2-eq?

(tuple2-eq? [t1 t2 e1-cmp e2-cmp])

compare two Tuple2 values element-wise using supplied comparators. Mirrors stdlib/pair.tur's pair-eq? macro.

t1first Tuple2[A B]
t2second Tuple2[A B]
e1-cmpcomparator for the first element (fn [a b] :bool)
e2-cmpcomparator for the second element (fn [a b] :bool)

true if both elements are equal under their comparators.

(tuple2-eq? (tuple2 1 2) (tuple2 1 2)
            (fn [a b] (= a b)) (fn [a b] (= a b)))  ; => true

Since: Phase TP2

defn

tuple2-eq-carrier?

(tuple2-eq-carrier? [t1 :int t2 :int e1-cmp e2-cmp])

legacy carrier-ABI helper used inside Tuple2's Eq instance. Mirrors stdlib/pair.tur's pair-eq-carrier?; subject to the same pre-existing typeclass-dispatch-on-parametric-struct issue that affects Eq [Pair] and Eq [Option]. Prefer the tuple2-eq? macro above for direct comparisons.

Since: Phase TP2

definstance

Eq[Tuple2]

(definstance Eq [Tuple2])