/*---------------------------------------------------------------------------
  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: ($144, $144) : (std/core/types/tuple2: (V, V) -> Vaa: V,aa: V), ff: ($144) -> $146 $145 : aa: V -> ee: E bb: V )result: -> 245 (244, 244) : 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: ($144, $144).fststd/core/types/tuple2/fst: (tuple2 : ($144, $144)) -> $146 $144.ff: ($144) -> $146 $145, tt: ($144, $144).sndstd/core/types/tuple2/snd: (tuple2 : ($144, $144)) -> $146 $144.ff: ($144) -> $146 $145)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: ($255, $255, $255) : (std/core/types/tuple3: (V, V, V) -> Vaa: V,aa: V,aa: V), ff: ($255) -> $257 $256 : aa: V -> ee: E bb: V )result: -> 398 (397, 397, 397) : 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: ($255, $255, $255).fststd/core/types/tuple3/fst: (tuple3 : ($255, $255, $255)) -> $257 $255.ff: ($255) -> $257 $256, tt: ($255, $255, $255).sndstd/core/types/tuple3/snd: (tuple3 : ($255, $255, $255)) -> $257 $255.ff: ($255) -> $257 $256, tt: ($255, $255, $255).thdstd/core/types/tuple3/thd: (tuple3 : ($255, $255, $255)) -> $257 $255.ff: ($255) -> $257 $256)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: ($408, $408, $408, $408) : (std/core/types/tuple4: (V, V, V, V) -> Vaa: V,aa: V,aa: V,aa: V), ff: ($408) -> $410 $409 : aa: V -> ee: E bb: V )result: -> 591 (590, 590, 590, 590) : 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: ($408, $408, $408, $408).fststd/core/types/tuple4/fst: (tuple4 : ($408, $408, $408, $408)) -> $410 $408.ff: ($408) -> $410 $409, tt: ($408, $408, $408, $408).sndstd/core/types/tuple4/snd: (tuple4 : ($408, $408, $408, $408)) -> $410 $408.ff: ($408) -> $410 $409, tt: ($408, $408, $408, $408).thdstd/core/types/tuple4/thd: (tuple4 : ($408, $408, $408, $408)) -> $410 $408.ff: ($408) -> $410 $409, tt: ($408, $408, $408, $408).field4std/core/types/tuple4/field4: (tuple4 : ($408, $408, $408, $408)) -> $410 $408.ff: ($408) -> $410 $409)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: $601,y1y1: $602)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: $601,y2y2: $602)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/(==): ($601, $601) -> bool : (aa: V,aa: V) -> boolstd/core/types/bool: V, (@implicit/snd/==)?snd/(==): ($602, $602) -> bool : (bb: V,bb: V) -> boolstd/core/types/bool: V )result: -> total bool : boolstd/core/types/bool: V
  (x1x1: $601==?fst/(==): ($601, $601) -> boolx2x2: $601) &&std/core/types/(&&): (x : bool, y : bool) -> bool (y1y1: $602==?snd/(==): ($602, $602) -> booly2y2: $602)

// 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: $670,y1y1: $671,z1z1: $672)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: $670,y2y2: $671,z2z2: $672)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/(==): ($670, $670) -> bool : (aa: V,aa: V) -> boolstd/core/types/bool: V, (@implicit/snd/==)?snd/(==): ($671, $671) -> bool : (bb: V,bb: V) -> boolstd/core/types/bool: V, (@implicit/thd/==)?thd/(==): ($672, $672) -> bool : (cc: V,cc: V) -> boolstd/core/types/bool: V )result: -> total bool : boolstd/core/types/bool: V
  (x1x1: $670==?fst/(==): ($670, $670) -> boolx2x2: $670) &&std/core/types/(&&): (x : bool, y : bool) -> bool (y1y1: $671==?snd/(==): ($671, $671) -> booly2y2: $671) &&std/core/types/(&&): (x : bool, y : bool) -> bool (z1z1: $672==?thd/(==): ($672, $672) -> boolz2z2: $672)


// 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: $787,y1y1: $788)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: $787,y2y2: $788)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: ($787, $787) -> order : (aa: V,aa: V) -> orderstd/core/types/order: V, @implicit/snd/cmp?snd/cmp: ($788, $788) -> order : (bb: V,bb: V) -> orderstd/core/types/order: V )result: -> total order : orderstd/core/types/order: V
  match fst/cmp?fst/cmp: ($787, $787) -> order(x1x1: $787,x2x2: $787)
    Eqstd/core/types/Eq: order -> snd/cmp?snd/cmp: ($788, $788) -> order(y1y1: $788,y2y2: $788)
    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: $831,y1y1: $832,z1z1: $833)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: $831,y2y2: $832,z2z2: $833)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: ($831, $831) -> order : (aa: V,aa: V) -> orderstd/core/types/order: V, ^@implicit/snd/cmp?snd/cmp: ($832, $832) -> order : (bb: V,bb: V) -> orderstd/core/types/order: V, ^@implicit/thd/cmp?thd/cmp: ($833, $833) -> order : (cc: V,cc: V) -> orderstd/core/types/order: V )result: -> total order : orderstd/core/types/order: V
  match fst/cmp?fst/cmp: ($831, $831) -> order(x1x1: $831,x2x2: $831)
    Eqstd/core/types/Eq: order -> match snd/cmp?snd/cmp: ($832, $832) -> order(y1y1: $832,y2y2: $832)
            Eqstd/core/types/Eq: order -> thd/cmp?thd/cmp: ($833, $833) -> order(z1z1: $833,z2z2: $833)
            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: ($915, $916) : (std/core/types/tuple2: (V, V) -> Vaa: V,bb: V), @implicit/fst/show?fst/show: ($915) -> $917 string : aa: V -> ee: E stringstd/core/types/string: V, @implicit/snd/show?snd/show: ($916) -> $917 string : bb: V -> ee: E stringstd/core/types/string: V)result: -> 1066 string : ee: E stringstd/core/types/string: V "("literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $917 string xx: ($915, $916).fststd/core/types/tuple2/fst: (tuple2 : ($915, $916)) -> $917 $915.show?fst/show: ($915) -> $917 string ++std/core/types/(++): (x : string, y : string) -> $917 string ","literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $917 string xx: ($915, $916).sndstd/core/types/tuple2/snd: (tuple2 : ($915, $916)) -> $917 $916.show?snd/show: ($916) -> $917 string ++std/core/types/(++): (x : string, y : string) -> $917 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: ($1067, $1068, $1069) : (std/core/types/tuple3: (V, V, V) -> Vaa: V,bb: V,cc: V), @implicit/fst/show?fst/show: ($1067) -> $1070 string : aa: V -> ee: E stringstd/core/types/string: V, @implicit/snd/show?snd/show: ($1068) -> $1070 string : bb: V -> ee: E stringstd/core/types/string: V, @implicit/thd/show?thd/show: ($1069) -> $1070 string : cc: V -> ee: E stringstd/core/types/string: V)result: -> 1292 string : ee: E stringstd/core/types/string: V "("literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $1070 string xx: ($1067, $1068, $1069).fststd/core/types/tuple3/fst: (tuple3 : ($1067, $1068, $1069)) -> $1070 $1067.show?fst/show: ($1067) -> $1070 string ++std/core/types/(++): (x : string, y : string) -> $1070 string ","literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $1070 string xx: ($1067, $1068, $1069).sndstd/core/types/tuple3/snd: (tuple3 : ($1067, $1068, $1069)) -> $1070 $1068.show?snd/show: ($1068) -> $1070 string ++std/core/types/(++): (x : string, y : string) -> $1070 string ","literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $1070 string xx: ($1067, $1068, $1069).thdstd/core/types/tuple3/thd: (tuple3 : ($1067, $1068, $1069)) -> $1070 $1069.show?thd/show: ($1069) -> $1070 string ++std/core/types/(++): (x : string, y : string) -> $1070 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: ($1314, $1315) : (std/core/types/tuple2: (V, V) -> Vaa: V,bb: V), showfstshowfst: ($1314) -> $1316 string : aa: V -> ee: E stringstd/core/types/string: V, showsndshowsnd: ($1315) -> $1316 string : bb: V -> ee: E stringstd/core/types/string: V )result: -> 1368 string : ee: E stringstd/core/types/string: V showstd/core/tuple/tuple2/show: (x : ($1314, $1315), @implicit/fst/show : ($1314) -> $1316 string, @implicit/snd/show : ($1315) -> $1316 string) -> $1316 string(xx: ($1314, $1315),@implicit/fst/show=showfstshowfst: ($1314) -> $1316 string,@implicit/snd/show=showsndshowsnd: ($1315) -> $1316 string)