/*---------------------------------------------------------------------------
  Copyright 2012-2024, Microsoft Research, Daan Leijen.

  This is free software; you can redistribute it and/or modify it under the
  terms of the Apache License, Version 2.0. A copy of the License can be
  found in the LICENSE file at the root of this distribution.
---------------------------------------------------------------------------*/

// Standard tuple functions.
module std/core/tuplestd/core/tuple

import std/core/typesstd/core/types
import std/core/hndstd/core/hnd

// Map a function over a tuple of elements of the same type.
pub fun tuple2/mapstd/core/tuple/tuple2/map: forall<a,b,e> (t : (a, a), f : (a) -> e b) -> e (b, b)( tt: ($148, $148) : (std/core/types/tuple2: (V, V) -> Vaa: V,aa: V), ff: ($148) -> $150 $149 : aa: V -> ee: E bb: V )result: -> 243 (242, 242) : ee: E (std/core/types/tuple2: (V, V) -> Vbb: V, bb: V)
  (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)tt: ($148, $148).fststd/core/types/tuple2/fst: (tuple2 : ($148, $148)) -> $150 $148.ff: ($148) -> $150 $149, tt: ($148, $148).sndstd/core/types/tuple2/snd: (tuple2 : ($148, $148)) -> $150 $148.ff: ($148) -> $150 $149)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)

// Map a function over a triple of elements of the same type.
pub fun tuple3/mapstd/core/tuple/tuple3/map: forall<a,b,e> (t : (a, a, a), f : (a) -> e b) -> e (b, b, b)( tt: ($253, $253, $253) : (std/core/types/tuple3: (V, V, V) -> Vaa: V,aa: V,aa: V), ff: ($253) -> $255 $254 : aa: V -> ee: E bb: V )result: -> 390 (389, 389, 389) : ee: E (std/core/types/tuple3: (V, V, V) -> Vbb: V, bb: V, bb: V)
  (std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)tt: ($253, $253, $253).fststd/core/types/tuple3/fst: (tuple3 : ($253, $253, $253)) -> $255 $253.ff: ($253) -> $255 $254, tt: ($253, $253, $253).sndstd/core/types/tuple3/snd: (tuple3 : ($253, $253, $253)) -> $255 $253.ff: ($253) -> $255 $254, tt: ($253, $253, $253).thdstd/core/types/tuple3/thd: (tuple3 : ($253, $253, $253)) -> $255 $253.ff: ($253) -> $255 $254)std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)

// Map a function over a quadruple of elements of the same type.
pub fun tuple4/mapstd/core/tuple/tuple4/map: forall<a,b,e> (t : (a, a, a, a), f : (a) -> e b) -> e (b, b, b, b)( tt: ($400, $400, $400, $400) : (std/core/types/tuple4: (V, V, V, V) -> Vaa: V,aa: V,aa: V,aa: V), ff: ($400) -> $402 $401 : aa: V -> ee: E bb: V )result: -> 577 (576, 576, 576, 576) : ee: E (std/core/types/tuple4: (V, V, V, V) -> Vbb: V,bb: V,bb: V,bb: V)
  (std/core/types/Tuple4: forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d)tt: ($400, $400, $400, $400).fststd/core/types/tuple4/fst: (tuple4 : ($400, $400, $400, $400)) -> $402 $400.ff: ($400) -> $402 $401, tt: ($400, $400, $400, $400).sndstd/core/types/tuple4/snd: (tuple4 : ($400, $400, $400, $400)) -> $402 $400.ff: ($400) -> $402 $401, tt: ($400, $400, $400, $400).thdstd/core/types/tuple4/thd: (tuple4 : ($400, $400, $400, $400)) -> $402 $400.ff: ($400) -> $402 $401, tt: ($400, $400, $400, $400).field4std/core/types/tuple4/field4: (tuple4 : ($400, $400, $400, $400)) -> $402 $400.ff: ($400) -> $402 $401)std/core/types/Tuple4: forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d)


// Element-wise tuple equality
pub fun tuple2/(==)std/core/tuple/tuple2/(==): forall<a,b> ((a, b), (a, b), @implicit/fst/(==) : (a, a) -> bool, @implicit/snd/(==) : (b, b) -> bool) -> bool( (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)x1x1: $1070,y1y1: $1071)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) : (std/core/types/tuple2: (V, V) -> Vaa: V,bb: V), (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)x2x2: $1070,y2y2: $1071)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) : (std/core/types/tuple2: (V, V) -> Vaa: V,bb: V), (@implicit/fst/==)?fst/(==): ($1070, $1070) -> bool : (aa: V,aa: V) -> boolstd/core/types/bool: V, (@implicit/snd/==)?snd/(==): ($1071, $1071) -> bool : (bb: V,bb: V) -> boolstd/core/types/bool: V )result: -> total bool : boolstd/core/types/bool: V
  (x1x1: $1070==?fst/(==): ($1070, $1070) -> boolx2x2: $1070) &&std/core/types/(&&): (x : bool, y : bool) -> bool (y1y1: $1071==?snd/(==): ($1071, $1071) -> booly2y2: $1071)

// Element-wise triple equality
pub fun tuple3/(==)std/core/tuple/tuple3/(==): forall<a,b,c> ((a, b, c), (a, b, c), @implicit/fst/(==) : (a, a) -> bool, @implicit/snd/(==) : (b, b) -> bool, @implicit/thd/(==) : (c, c) -> bool) -> bool( (std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)x1x1: $1131,y1y1: $1132,z1z1: $1133)std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c) : (std/core/types/tuple3: (V, V, V) -> Vaa: V,bb: V,cc: V), (std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)x2x2: $1131,y2y2: $1132,z2z2: $1133)std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c) : (std/core/types/tuple3: (V, V, V) -> Vaa: V,bb: V,cc: V), (@implicit/fst/==)?fst/(==): ($1131, $1131) -> bool : (aa: V,aa: V) -> boolstd/core/types/bool: V, (@implicit/snd/==)?snd/(==): ($1132, $1132) -> bool : (bb: V,bb: V) -> boolstd/core/types/bool: V, (@implicit/thd/==)?thd/(==): ($1133, $1133) -> bool : (cc: V,cc: V) -> boolstd/core/types/bool: V )result: -> total bool : boolstd/core/types/bool: V
  (x1x1: $1131==?fst/(==): ($1131, $1131) -> boolx2x2: $1131) &&std/core/types/(&&): (x : bool, y : bool) -> bool (y1y1: $1132==?snd/(==): ($1132, $1132) -> booly2y2: $1132) &&std/core/types/(&&): (x : bool, y : bool) -> bool (z1z1: $1133==?thd/(==): ($1133, $1133) -> boolz2z2: $1133)


// Order on tuples
pub fun tuple2/cmpstd/core/tuple/tuple2/cmp: forall<a,b> ((a, b), (a, b), @implicit/fst/cmp : (a, a) -> order, @implicit/snd/cmp : (b, b) -> order) -> order( (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)x1x1: $1236,y1y1: $1237)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) : (std/core/types/tuple2: (V, V) -> Vaa: V,bb: V), (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)x2x2: $1236,y2y2: $1237)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) : (std/core/types/tuple2: (V, V) -> Vaa: V,bb: V), @implicit/fst/cmp?fst/cmp: ($1236, $1236) -> order : (aa: V,aa: V) -> orderstd/core/types/order: V, @implicit/snd/cmp?snd/cmp: ($1237, $1237) -> order : (bb: V,bb: V) -> orderstd/core/types/order: V )result: -> total order : orderstd/core/types/order: V
  match fst/cmp?fst/cmp: ($1236, $1236) -> order(x1x1: $1236,x2x2: $1236)
    Eqstd/core/types/Eq: order -> snd/cmp?snd/cmp: ($1237, $1237) -> order(y1y1: $1237,y2y2: $1237)
    lglg: order -> lglg: order

// Order on triples
pub fbip fun tuple3/cmpstd/core/tuple/tuple3/cmp: forall<a,b,c> ((a, b, c), (a, b, c), @implicit/fst/cmp : (a, a) -> order, @implicit/snd/cmp : (b, b) -> order, @implicit/thd/cmp : (c, c) -> order) -> order( (std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)x1x1: $1272,y1y1: $1273,z1z1: $1274)std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c) : (std/core/types/tuple3: (V, V, V) -> Vaa: V,bb: V,cc: V), (std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)x2x2: $1272,y2y2: $1273,z2z2: $1274)std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c) : (std/core/types/tuple3: (V, V, V) -> Vaa: V,bb: V,cc: V), ^@implicit/fst/cmp?fst/cmp: ($1272, $1272) -> order : (aa: V,aa: V) -> orderstd/core/types/order: V, ^@implicit/snd/cmp?snd/cmp: ($1273, $1273) -> order : (bb: V,bb: V) -> orderstd/core/types/order: V, ^@implicit/thd/cmp?thd/cmp: ($1274, $1274) -> order : (cc: V,cc: V) -> orderstd/core/types/order: V )result: -> total order : orderstd/core/types/order: V
  match fst/cmp?fst/cmp: ($1272, $1272) -> order(x1x1: $1272,x2x2: $1272)
    Eqstd/core/types/Eq: order -> match snd/cmp?snd/cmp: ($1273, $1273) -> order(y1y1: $1273,y2y2: $1273)
            Eqstd/core/types/Eq: order -> thd/cmp?thd/cmp: ($1274, $1274) -> order(z1z1: $1274,z2z2: $1274)
            lglg: order -> lglg: order
    lglg: order -> lglg: order


// Convert a unit value `()` to a string
pub fun unit/showstd/core/tuple/unit/show: (u : ()) -> string( uu: () : (std/core/types/unit: V)std/core/types/unit: V )result: -> total string : stringstd/core/types/string: V
  "()"literal: string
count= 2
// Show a tuple pub fun tuple2/showstd/core/tuple/tuple2/show: forall<a,b,e> (x : (a, b), @implicit/fst/show : (a) -> e string, @implicit/snd/show : (b) -> e string) -> e string( xx: ($587, $588) : (std/core/types/tuple2: (V, V) -> Vaa: V,bb: V), @implicit/fst/show?fst/show: ($587) -> $589 string : aa: V -> ee: E stringstd/core/types/string: V, @implicit/snd/show?snd/show: ($588) -> $589 string : bb: V -> ee: E stringstd/core/types/string: V)result: -> 748 string : ee: E stringstd/core/types/string: V "("literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $589 string xx: ($587, $588).fststd/core/types/tuple2/fst: (tuple2 : ($587, $588)) -> $589 $587.show?fst/show: ($587) -> $589 string ++std/core/types/(++): (x : string, y : string) -> $589 string ","literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $589 string xx: ($587, $588).sndstd/core/types/tuple2/snd: (tuple2 : ($587, $588)) -> $589 $588.show?snd/show: ($588) -> $589 string ++std/core/types/(++): (x : string, y : string) -> $589 string ")"literal: string
count= 1
// Show a triple pub fun tuple3/showstd/core/tuple/tuple3/show: forall<a,b,c,e> (x : (a, b, c), @implicit/fst/show : (a) -> e string, @implicit/snd/show : (b) -> e string, @implicit/thd/show : (c) -> e string) -> e string( xx: ($749, $750, $751) : (std/core/types/tuple3: (V, V, V) -> Vaa: V,bb: V,cc: V), @implicit/fst/show?fst/show: ($749) -> $752 string : aa: V -> ee: E stringstd/core/types/string: V, @implicit/snd/show?snd/show: ($750) -> $752 string : bb: V -> ee: E stringstd/core/types/string: V, @implicit/thd/show?thd/show: ($751) -> $752 string : cc: V -> ee: E stringstd/core/types/string: V)result: -> 990 string : ee: E stringstd/core/types/string: V "("literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $752 string xx: ($749, $750, $751).fststd/core/types/tuple3/fst: (tuple3 : ($749, $750, $751)) -> $752 $749.show?fst/show: ($749) -> $752 string ++std/core/types/(++): (x : string, y : string) -> $752 string ","literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $752 string xx: ($749, $750, $751).sndstd/core/types/tuple3/snd: (tuple3 : ($749, $750, $751)) -> $752 $750.show?snd/show: ($750) -> $752 string ++std/core/types/(++): (x : string, y : string) -> $752 string ","literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $752 string xx: ($749, $750, $751).thdstd/core/types/tuple3/thd: (tuple3 : ($749, $750, $751)) -> $752 $751.show?thd/show: ($751) -> $752 string ++std/core/types/(++): (x : string, y : string) -> $752 string ")"literal: string
count= 1
// _deprecated_, use `tuple2/show` instead pub fun show-tuplestd/core/tuple/show-tuple: forall<a,b,e> (x : (a, b), showfst : (a) -> e string, showsnd : (b) -> e string) -> e string( xx: ($1012, $1013) : (std/core/types/tuple2: (V, V) -> Vaa: V,bb: V), showfstshowfst: ($1012) -> $1014 string : aa: V -> ee: E stringstd/core/types/string: V, showsndshowsnd: ($1013) -> $1014 string : bb: V -> ee: E stringstd/core/types/string: V )result: -> 1060 string : ee: E stringstd/core/types/string: V showstd/core/tuple/tuple2/show: (x : ($1012, $1013), @implicit/fst/show : ($1012) -> $1014 string, @implicit/snd/show : ($1013) -> $1014 string) -> $1014 string(xx: ($1012, $1013),@implicit/fst/show=showfstshowfst: ($1012) -> $1014 string,@implicit/snd/show=showsndshowsnd: ($1013) -> $1014 string)