├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── ci.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bower.json ├── package.json └── src └── Data ├── Tuple.purs └── Tuple └── Nested.purs /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Description of the change** 2 | 3 | Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR. 4 | 5 | --- 6 | 7 | **Checklist:** 8 | 9 | - [ ] Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)") 10 | - [ ] Linked any existing issues or proposals that this pull request should close 11 | - [ ] Updated or added relevant documentation 12 | - [ ] Added a test for the contribution (if applicable) 13 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: 7 | branches: [master] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | 15 | - uses: purescript-contrib/setup-purescript@main 16 | with: 17 | purescript: "unstable" 18 | 19 | - uses: actions/setup-node@v2 20 | with: 21 | node-version: "14.x" 22 | 23 | - name: Install dependencies 24 | run: | 25 | npm install -g bower 26 | npm install 27 | bower install --production 28 | 29 | - name: Build source 30 | run: npm run-script build 31 | 32 | - name: Run tests 33 | run: | 34 | bower install 35 | npm run-script test --if-present 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.* 2 | !/.gitignore 3 | !/.github/ 4 | /bower_components/ 5 | /node_modules/ 6 | /output/ 7 | package-lock.json 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 4 | 5 | ## [Unreleased] 6 | 7 | Breaking changes: 8 | 9 | New features: 10 | 11 | Bugfixes: 12 | 13 | Other improvements: 14 | 15 | ## [v7.0.0](https://github.com/purescript/purescript-tuples/releases/tag/v7.0.0) - 2022-04-27 16 | 17 | Breaking changes: 18 | - Update project and deps to PureScript v0.15.0 (#50 by @JordanMartinez) 19 | 20 | New features: 21 | 22 | Bugfixes: 23 | 24 | Other improvements: 25 | 26 | ## [v6.0.1](https://github.com/purescript/purescript-tuples/releases/tag/v6.0.1) - 2021-04-27 27 | 28 | Other improvements: 29 | - Fix warnings revealed by v0.14.1 PS release (#48 by @JordanMartinez) 30 | 31 | ## [v6.0.0](https://github.com/purescript/purescript-tuples/releases/tag/v6.0.0) - 2021-02-26 32 | 33 | Breaking changes: 34 | - Added support for PureScript 0.14 and dropped support for all previous versions (#37, #43) 35 | - `Data.Tuple.lookup` has been moved to `Data.Foldable.lookup` in the `purescript-foldable-traversable` package (#46) 36 | 37 | New features: 38 | - Added Generic instance for Tuple (#40) 39 | - This package no longer depends on the `purescript-bifunctors`, `purescript-distributive`, `purescript-foldable-traversable`, `purescript-maybe`, `purescript-newtype`, and `purescript-type-equality` packages. Relevant instances have been moved to those packages. (#46) 40 | 41 | Bugfixes: 42 | 43 | Other improvements: 44 | - Added `foldr1` and `foldl1` implementations to `Foldable1 (Tuple a)` instance and removed `fold1` (#39, #43) 45 | - Improved and expanded documentation in the module header (#30) 46 | - Fixed mistaken reference to `Functor` in documentation comment for `Apply` instance (#33) 47 | - Migrated CI to GitHub Actions and updated installation instructions to use Spago (#42) 48 | - Added a changelog and pull request template (#44, #45) 49 | 50 | ## [v5.1.0](https://github.com/purescript/purescript-tuples/releases/tag/v5.1.0) - 2018-10-28 51 | 52 | - Added `Foldable1`, `FoldableWithIndex`, `Traversable1`, `TraversableWithIndex` instances (@MonoidMusician) 53 | 54 | ## [v5.0.0](https://github.com/purescript/purescript-tuples/releases/tag/v5.0.0) - 2018-05-23 55 | 56 | - Updated for PureScript 0.12 57 | 58 | ## [v4.1.0](https://github.com/purescript/purescript-tuples/releases/tag/v4.1.0) - 2017-05-28 59 | 60 | - Add `Distributive` instance (@matthewleon) 61 | 62 | ## [v4.0.0](https://github.com/purescript/purescript-tuples/releases/tag/v4.0.0) - 2017-03-26 63 | 64 | - Updated for PureScript 0.11 65 | 66 | ## [v3.2.0](https://github.com/purescript/purescript-tuples/releases/tag/v3.2.0) - 2017-03-02 67 | 68 | - Added `Eq1` and `Ord1` instances 69 | 70 | ## [v3.1.0](https://github.com/purescript/purescript-tuples/releases/tag/v3.1.0) - 2016-12-29 71 | 72 | - Added type operator alias for `/\` (@damncabbage) 73 | 74 | ## [v3.0.0](https://github.com/purescript/purescript-tuples/releases/tag/v3.0.0) - 2016-10-05 75 | 76 | - Nested tuple operations are now "open" (extensible) 77 | 78 | ## [v2.0.0](https://github.com/purescript/purescript-tuples/releases/tag/v2.0.0) - 2016-10-03 79 | 80 | - Updated dependencies 81 | - `Nested` tuples are now right-nested for consistency with the updates to `Either` 82 | 83 | ## [v1.0.0](https://github.com/purescript/purescript-tuples/releases/tag/v1.0.0) - 2016-06-01 84 | 85 | This release is intended for the PureScript 0.9.1 compiler and newer. 86 | - Updated for new `Prelude` class hierarchies 87 | 88 | **Note**: The v1.0.0 tag is not meant to indicate the library is “finished”, the core libraries are all being bumped to this for the 0.9 compiler release so as to use semver more correctly. 89 | 90 | ## [v0.4.0](https://github.com/purescript/purescript-tuples/releases/tag/v0.4.0) - 2015-06-30 91 | 92 | This release works with versions 0.7.\* of the PureScript compiler. It will not work with older versions. If you are using an older version, you should require an older, compatible version of this library. 93 | 94 | ## [v0.3.4](https://github.com/purescript/purescript-tuples/releases/tag/v0.3.4) - 2015-03-25 95 | 96 | - Improvements to nested tuples (@natefaubion) 97 | 98 | ## [v0.3.3](https://github.com/purescript/purescript-tuples/releases/tag/v0.3.3) - 2015-03-25 99 | 100 | - More updates to nested tuples (@jdegoes) 101 | 102 | ## [v0.3.2](https://github.com/purescript/purescript-tuples/releases/tag/v0.3.2) - 2015-03-24 103 | 104 | - Rework nested tuples (@jdegoes) 105 | 106 | ## [v0.3.1](https://github.com/purescript/purescript-tuples/releases/tag/v0.3.1) - 2015-03-19 107 | 108 | - Updated docs (@brainrape) 109 | 110 | ## [v0.3.0](https://github.com/purescript/purescript-tuples/releases/tag/v0.3.0) - 2015-02-21 111 | 112 | **This release requires PureScript v0.6.8 or later** 113 | - Updated `purescript-monoid` dependency 114 | 115 | ## [v0.2.3](https://github.com/purescript/purescript-tuples/releases/tag/v0.2.3) - 2014-12-01 116 | 117 | - Updated dependencies 118 | 119 | ## [v0.2.2](https://github.com/purescript/purescript-tuples/releases/tag/v0.2.2) - 2014-11-05 120 | 121 | - Ease pain of working with nested tuples 122 | 123 | ## [v0.2.1](https://github.com/purescript/purescript-tuples/releases/tag/v0.2.1) - 2014-09-08 124 | 125 | - Added `Comonad`, `Extract`, `Monoid`, `Semigroup`, and `Semigroupoid` instances (@joneshf) 126 | 127 | ## [v0.2.0](https://github.com/purescript/purescript-tuples/releases/tag/v0.2.0) - 2014-08-11 128 | 129 | - Add instances for `Lazy` (@garyb) 130 | 131 | ## [v0.1.2](https://github.com/purescript/purescript-tuples/releases/tag/v0.1.2) - 2014-06-14 132 | 133 | - Fixed `Show` instance (garyb) 134 | 135 | ## [v0.1.1](https://github.com/purescript/purescript-tuples/releases/tag/v0.1.1) - 2014-04-25 136 | 137 | - Removed test-related stuff (moved to core-tests) 138 | 139 | ## [v0.1.0](https://github.com/purescript/purescript-tuples/releases/tag/v0.1.0) - 2014-04-21 140 | 141 | - Initial release 142 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 PureScript 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation and/or 11 | other materials provided with the distribution. 12 | 13 | 3. Neither the name of the copyright holder nor the names of its contributors 14 | may be used to endorse or promote products derived from this software without 15 | specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # purescript-tuples 2 | 3 | [![Latest release](http://img.shields.io/github/release/purescript/purescript-tuples.svg)](https://github.com/purescript/purescript-tuples/releases) 4 | [![Build status](https://github.com/purescript/purescript-tuples/workflows/CI/badge.svg?branch=master)](https://github.com/purescript/purescript-tuples/actions?query=workflow%3ACI+branch%3Amaster) 5 | [![Pursuit](https://pursuit.purescript.org/packages/purescript-tuples/badge)](https://pursuit.purescript.org/packages/purescript-tuples) 6 | 7 | Tuple data type and utility functions. 8 | 9 | ## Installation 10 | 11 | ``` 12 | spago install tuples 13 | ``` 14 | 15 | ## Documentation 16 | 17 | Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-tuples). 18 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "purescript-tuples", 3 | "homepage": "https://github.com/purescript/purescript-tuples", 4 | "license": "BSD-3-Clause", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/purescript/purescript-tuples.git" 8 | }, 9 | "ignore": [ 10 | "**/.*", 11 | "bower_components", 12 | "node_modules", 13 | "output", 14 | "test", 15 | "bower.json", 16 | "package.json" 17 | ], 18 | "dependencies": { 19 | "purescript-control": "^6.0.0", 20 | "purescript-invariant": "^6.0.0", 21 | "purescript-prelude": "^6.0.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "clean": "rimraf output && rimraf .pulp-cache", 5 | "build": "pulp build -- --censor-lib --strict" 6 | }, 7 | "devDependencies": { 8 | "pulp": "16.0.0-0", 9 | "purescript-psa": "^0.8.2", 10 | "rimraf": "^3.0.2" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Data/Tuple.purs: -------------------------------------------------------------------------------- 1 | -- | A data type and functions for working with ordered pairs. 2 | module Data.Tuple where 3 | 4 | import Prelude 5 | 6 | import Control.Comonad (class Comonad) 7 | import Control.Extend (class Extend) 8 | import Control.Lazy (class Lazy, defer) 9 | import Data.Eq (class Eq1) 10 | import Data.Functor.Invariant (class Invariant, imapF) 11 | import Data.Generic.Rep (class Generic) 12 | import Data.HeytingAlgebra (implies, ff, tt) 13 | import Data.Ord (class Ord1) 14 | 15 | -- | A simple product type for wrapping a pair of component values. 16 | data Tuple a b = Tuple a b 17 | 18 | -- | Allows `Tuple`s to be rendered as a string with `show` whenever there are 19 | -- | `Show` instances for both component types. 20 | instance showTuple :: (Show a, Show b) => Show (Tuple a b) where 21 | show (Tuple a b) = "(Tuple " <> show a <> " " <> show b <> ")" 22 | 23 | -- | Allows `Tuple`s to be checked for equality with `==` and `/=` whenever 24 | -- | there are `Eq` instances for both component types. 25 | derive instance eqTuple :: (Eq a, Eq b) => Eq (Tuple a b) 26 | 27 | derive instance eq1Tuple :: Eq a => Eq1 (Tuple a) 28 | 29 | -- | Allows `Tuple`s to be compared with `compare`, `>`, `>=`, `<` and `<=` 30 | -- | whenever there are `Ord` instances for both component types. To obtain 31 | -- | the result, the `fst`s are `compare`d, and if they are `EQ`ual, the 32 | -- | `snd`s are `compare`d. 33 | derive instance ordTuple :: (Ord a, Ord b) => Ord (Tuple a b) 34 | 35 | derive instance ord1Tuple :: Ord a => Ord1 (Tuple a) 36 | 37 | instance boundedTuple :: (Bounded a, Bounded b) => Bounded (Tuple a b) where 38 | top = Tuple top top 39 | bottom = Tuple bottom bottom 40 | 41 | instance semigroupoidTuple :: Semigroupoid Tuple where 42 | compose (Tuple _ c) (Tuple a _) = Tuple a c 43 | 44 | -- | The `Semigroup` instance enables use of the associative operator `<>` on 45 | -- | `Tuple`s whenever there are `Semigroup` instances for the component 46 | -- | types. The `<>` operator is applied pairwise, so: 47 | -- | ```purescript 48 | -- | (Tuple a1 b1) <> (Tuple a2 b2) = Tuple (a1 <> a2) (b1 <> b2) 49 | -- | ``` 50 | instance semigroupTuple :: (Semigroup a, Semigroup b) => Semigroup (Tuple a b) where 51 | append (Tuple a1 b1) (Tuple a2 b2) = Tuple (a1 <> a2) (b1 <> b2) 52 | 53 | instance monoidTuple :: (Monoid a, Monoid b) => Monoid (Tuple a b) where 54 | mempty = Tuple mempty mempty 55 | 56 | instance semiringTuple :: (Semiring a, Semiring b) => Semiring (Tuple a b) where 57 | add (Tuple x1 y1) (Tuple x2 y2) = Tuple (add x1 x2) (add y1 y2) 58 | one = Tuple one one 59 | mul (Tuple x1 y1) (Tuple x2 y2) = Tuple (mul x1 x2) (mul y1 y2) 60 | zero = Tuple zero zero 61 | 62 | instance ringTuple :: (Ring a, Ring b) => Ring (Tuple a b) where 63 | sub (Tuple x1 y1) (Tuple x2 y2) = Tuple (sub x1 x2) (sub y1 y2) 64 | 65 | instance commutativeRingTuple :: (CommutativeRing a, CommutativeRing b) => CommutativeRing (Tuple a b) 66 | 67 | instance heytingAlgebraTuple :: (HeytingAlgebra a, HeytingAlgebra b) => HeytingAlgebra (Tuple a b) where 68 | tt = Tuple tt tt 69 | ff = Tuple ff ff 70 | implies (Tuple x1 y1) (Tuple x2 y2) = Tuple (x1 `implies` x2) (y1 `implies` y2) 71 | conj (Tuple x1 y1) (Tuple x2 y2) = Tuple (conj x1 x2) (conj y1 y2) 72 | disj (Tuple x1 y1) (Tuple x2 y2) = Tuple (disj x1 x2) (disj y1 y2) 73 | not (Tuple x y) = Tuple (not x) (not y) 74 | 75 | instance booleanAlgebraTuple :: (BooleanAlgebra a, BooleanAlgebra b) => BooleanAlgebra (Tuple a b) 76 | 77 | -- | The `Functor` instance allows functions to transform the contents of a 78 | -- | `Tuple` with the `<$>` operator, applying the function to the second 79 | -- | component, so: 80 | -- | ```purescript 81 | -- | f <$> (Tuple x y) = Tuple x (f y) 82 | -- | ```` 83 | derive instance functorTuple :: Functor (Tuple a) 84 | 85 | derive instance genericTuple :: Generic (Tuple a b) _ 86 | 87 | instance invariantTuple :: Invariant (Tuple a) where 88 | imap = imapF 89 | 90 | -- | The `Apply` instance allows functions to transform the contents of a 91 | -- | `Tuple` with the `<*>` operator whenever there is a `Semigroup` instance 92 | -- | for the `fst` component, so: 93 | -- | ```purescript 94 | -- | (Tuple a1 f) <*> (Tuple a2 x) == Tuple (a1 <> a2) (f x) 95 | -- | ``` 96 | instance applyTuple :: (Semigroup a) => Apply (Tuple a) where 97 | apply (Tuple a1 f) (Tuple a2 x) = Tuple (a1 <> a2) (f x) 98 | 99 | instance applicativeTuple :: (Monoid a) => Applicative (Tuple a) where 100 | pure = Tuple mempty 101 | 102 | instance bindTuple :: (Semigroup a) => Bind (Tuple a) where 103 | bind (Tuple a1 b) f = case f b of 104 | Tuple a2 c -> Tuple (a1 <> a2) c 105 | 106 | instance monadTuple :: (Monoid a) => Monad (Tuple a) 107 | 108 | instance extendTuple :: Extend (Tuple a) where 109 | extend f t@(Tuple a _) = Tuple a (f t) 110 | 111 | instance comonadTuple :: Comonad (Tuple a) where 112 | extract = snd 113 | 114 | instance lazyTuple :: (Lazy a, Lazy b) => Lazy (Tuple a b) where 115 | defer f = Tuple (defer $ \_ -> fst (f unit)) (defer $ \_ -> snd (f unit)) 116 | 117 | -- | Returns the first component of a tuple. 118 | fst :: forall a b. Tuple a b -> a 119 | fst (Tuple a _) = a 120 | 121 | -- | Returns the second component of a tuple. 122 | snd :: forall a b. Tuple a b -> b 123 | snd (Tuple _ b) = b 124 | 125 | -- | Turn a function that expects a tuple into a function of two arguments. 126 | curry :: forall a b c. (Tuple a b -> c) -> a -> b -> c 127 | curry f a b = f (Tuple a b) 128 | 129 | -- | Turn a function of two arguments into a function that expects a tuple. 130 | uncurry :: forall a b c. (a -> b -> c) -> Tuple a b -> c 131 | uncurry f (Tuple a b) = f a b 132 | 133 | -- | Exchange the first and second components of a tuple. 134 | swap :: forall a b. Tuple a b -> Tuple b a 135 | swap (Tuple a b) = Tuple b a 136 | -------------------------------------------------------------------------------- /src/Data/Tuple/Nested.purs: -------------------------------------------------------------------------------- 1 | -- | Tuples that are not restricted to two elements. 2 | -- | 3 | -- | Here is an example of a 3-tuple: 4 | -- | 5 | -- | 6 | -- | ```purescript 7 | -- | > tuple = tuple3 1 "2" 3.0 8 | -- | > tuple 9 | -- | (Tuple 1 (Tuple "2" (Tuple 3.0 unit))) 10 | -- | ``` 11 | -- | 12 | -- | Notice that a tuple is a nested structure not unlike a list. The type of `tuple` is this: 13 | -- | 14 | -- | ```purescript 15 | -- | > :t tuple 16 | -- | Tuple Int (Tuple String (Tuple Number Unit)) 17 | -- | ``` 18 | -- | 19 | -- | That, however, can be abbreviated with the `Tuple3` type: 20 | -- | 21 | -- | ```purescript 22 | -- | Tuple3 Int String Number 23 | -- | ``` 24 | -- | 25 | -- | All tuple functions are numbered from 1 to 10. That is, there's 26 | -- | a `get1` and a `get10`. 27 | -- | 28 | -- | The `getN` functions accept tuples of length N or greater: 29 | -- | 30 | -- | ```purescript 31 | -- | get1 tuple = 1 32 | -- | get3 tuple = 3 33 | -- | get4 tuple -- type error. `get4` requires a longer tuple. 34 | -- | ``` 35 | -- | 36 | -- | The same is true of the `overN` functions: 37 | -- | 38 | -- | ```purescript 39 | -- | over2 negate (tuple3 1 2 3) = tuple3 1 (-2) 3 40 | -- | ``` 41 | -- | 42 | 43 | -- | `uncurryN` can be used to convert a function that takes `N` arguments to one that takes an N-tuple: 44 | -- | 45 | -- | ```purescript 46 | -- | uncurry2 (+) (tuple2 1 2) = 3 47 | -- | ``` 48 | -- | 49 | -- | The reverse `curryN` function converts functions that take 50 | -- | N-tuples (which are rare) to functions that take `N` arguments. 51 | -- | 52 | -- | --------------- 53 | -- | In addition to types like `Tuple3`, there are also types like 54 | -- | `T3`. Whereas `Tuple3` describes a tuple with exactly three 55 | -- | elements, `T3` describes a tuple of length *two or longer*. More 56 | -- | specifically, `T3` requires two element plus a "tail" that may be 57 | -- | `unit` or more tuple elements. Use types like `T3` when you want to 58 | -- | create a set of functions for arbitrary tuples. See the source for how that's done. 59 | -- | 60 | module Data.Tuple.Nested where 61 | 62 | import Prelude 63 | import Data.Tuple (Tuple(..)) 64 | 65 | -- | Shorthand for constructing n-tuples as nested pairs. 66 | -- | `a /\ b /\ c /\ d /\ unit` becomes `Tuple a (Tuple b (Tuple c (Tuple d unit)))` 67 | infixr 6 Tuple as /\ 68 | 69 | -- | Shorthand for constructing n-tuple types as nested pairs. 70 | -- | `forall a b c d. a /\ b /\ c /\ d /\ Unit` becomes 71 | -- | `forall a b c d. Tuple a (Tuple b (Tuple c (Tuple d Unit)))` 72 | infixr 6 type Tuple as /\ 73 | 74 | type Tuple1 a = T2 a Unit 75 | type Tuple2 a b = T3 a b Unit 76 | type Tuple3 a b c = T4 a b c Unit 77 | type Tuple4 a b c d = T5 a b c d Unit 78 | type Tuple5 a b c d e= T6 a b c d e Unit 79 | type Tuple6 a b c d e f = T7 a b c d e f Unit 80 | type Tuple7 a b c d e f g = T8 a b c d e f g Unit 81 | type Tuple8 a b c d e f g h = T9 a b c d e f g h Unit 82 | type Tuple9 a b c d e f g h i = T10 a b c d e f g h i Unit 83 | type Tuple10 a b c d e f g h i j = T11 a b c d e f g h i j Unit 84 | 85 | type T2 a z = Tuple a z 86 | type T3 a b z = Tuple a (T2 b z) 87 | type T4 a b c z = Tuple a (T3 b c z) 88 | type T5 a b c d z = Tuple a (T4 b c d z) 89 | type T6 a b c d e z = Tuple a (T5 b c d e z) 90 | type T7 a b c d e f z = Tuple a (T6 b c d e f z) 91 | type T8 a b c d e f g z = Tuple a (T7 b c d e f g z) 92 | type T9 a b c d e f g h z = Tuple a (T8 b c d e f g h z) 93 | type T10 a b c d e f g h i z = Tuple a (T9 b c d e f g h i z) 94 | type T11 a b c d e f g h i j z = Tuple a (T10 b c d e f g h i j z) 95 | 96 | -- | Creates a singleton tuple. 97 | tuple1 :: forall a. a -> Tuple1 a 98 | tuple1 a = a /\ unit 99 | 100 | -- | Given 2 values, creates a 2-tuple. 101 | tuple2 :: forall a b. a -> b -> Tuple2 a b 102 | tuple2 a b = a /\ b /\ unit 103 | 104 | -- | Given 3 values, creates a nested 3-tuple. 105 | tuple3 :: forall a b c. a -> b -> c -> Tuple3 a b c 106 | tuple3 a b c = a /\ b /\ c /\ unit 107 | 108 | -- | Given 4 values, creates a nested 4-tuple. 109 | tuple4 :: forall a b c d. a -> b -> c -> d -> Tuple4 a b c d 110 | tuple4 a b c d = a /\ b /\ c /\ d /\ unit 111 | 112 | -- | Given 5 values, creates a nested 5-tuple. 113 | tuple5 :: forall a b c d e. a -> b -> c -> d -> e -> Tuple5 a b c d e 114 | tuple5 a b c d e = a /\ b /\ c /\ d /\ e /\ unit 115 | 116 | -- | Given 6 values, creates a nested 6-tuple. 117 | tuple6 :: forall a b c d e f. a -> b -> c -> d -> e -> f -> Tuple6 a b c d e f 118 | tuple6 a b c d e f = a /\ b /\ c /\ d /\ e /\ f /\ unit 119 | 120 | -- | Given 7 values, creates a nested 7-tuple. 121 | tuple7 :: forall a b c d e f g. a -> b -> c -> d -> e -> f -> g -> Tuple7 a b c d e f g 122 | tuple7 a b c d e f g = a /\ b /\ c /\ d /\ e /\ f /\ g /\ unit 123 | 124 | -- | Given 8 values, creates a nested 8-tuple. 125 | tuple8 :: forall a b c d e f g h. a -> b -> c -> d -> e -> f -> g -> h -> Tuple8 a b c d e f g h 126 | tuple8 a b c d e f g h = a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ unit 127 | 128 | -- | Given 9 values, creates a nested 9-tuple. 129 | tuple9 :: forall a b c d e f g h i. a -> b -> c -> d -> e -> f -> g -> h -> i -> Tuple9 a b c d e f g h i 130 | tuple9 a b c d e f g h i = a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ i /\ unit 131 | 132 | -- | Given 10 values, creates a nested 10-tuple. 133 | tuple10 :: forall a b c d e f g h i j. a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> Tuple10 a b c d e f g h i j 134 | tuple10 a b c d e f g h i j = a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ i /\ j /\ unit 135 | 136 | -- | Given at least a singleton tuple, gets the first value. 137 | get1 :: forall a z. T2 a z -> a 138 | get1 (a /\ _) = a 139 | 140 | -- | Given at least a 2-tuple, gets the second value. 141 | get2 :: forall a b z. T3 a b z -> b 142 | get2 (_ /\ b /\ _) = b 143 | 144 | -- | Given at least a 3-tuple, gets the third value. 145 | get3 :: forall a b c z. T4 a b c z -> c 146 | get3 (_ /\ _ /\ c /\ _) = c 147 | 148 | -- | Given at least a 4-tuple, gets the fourth value. 149 | get4 :: forall a b c d z. T5 a b c d z -> d 150 | get4 (_ /\ _ /\ _ /\ d /\ _) = d 151 | 152 | -- | Given at least a 5-tuple, gets the fifth value. 153 | get5 :: forall a b c d e z. T6 a b c d e z -> e 154 | get5 (_ /\ _ /\ _ /\ _ /\ e /\ _) = e 155 | 156 | -- | Given at least a 6-tuple, gets the sixth value. 157 | get6 :: forall a b c d e f z. T7 a b c d e f z -> f 158 | get6 (_ /\ _ /\ _ /\ _ /\ _ /\ f /\ _) = f 159 | 160 | -- | Given at least a 7-tuple, gets the seventh value. 161 | get7 :: forall a b c d e f g z. T8 a b c d e f g z -> g 162 | get7 (_ /\ _ /\ _ /\ _ /\ _ /\ _ /\ g /\ _) = g 163 | 164 | -- | Given at least an 8-tuple, gets the eigth value. 165 | get8 :: forall a b c d e f g h z. T9 a b c d e f g h z -> h 166 | get8 (_ /\ _ /\ _ /\ _ /\ _ /\ _ /\ _ /\ h /\ _) = h 167 | 168 | -- | Given at least a 9-tuple, gets the ninth value. 169 | get9 :: forall a b c d e f g h i z. T10 a b c d e f g h i z -> i 170 | get9 (_ /\ _ /\ _ /\ _ /\ _ /\ _ /\ _ /\ _ /\ i /\ _) = i 171 | 172 | -- | Given at least a 10-tuple, gets the tenth value. 173 | get10 :: forall a b c d e f g h i j z. T11 a b c d e f g h i j z -> j 174 | get10 (_ /\ _ /\ _ /\ _ /\ _ /\ _ /\ _ /\ _ /\ _ /\ j /\ _) = j 175 | 176 | -- | Given at least a singleton tuple, modifies the first value. 177 | over1 :: forall a r z. (a -> r) -> T2 a z -> T2 r z 178 | over1 o (a /\ z) = o a /\ z 179 | 180 | -- | Given at least a 2-tuple, modifies the second value. 181 | over2 :: forall a b r z. (b -> r) -> T3 a b z -> T3 a r z 182 | over2 o (a /\ b /\ z) = a /\ o b /\ z 183 | 184 | -- | Given at least a 3-tuple, modifies the third value. 185 | over3 :: forall a b c r z. (c -> r) -> T4 a b c z -> T4 a b r z 186 | over3 o (a /\ b /\ c /\ z) = a /\ b /\ o c /\ z 187 | 188 | -- | Given at least a 4-tuple, modifies the fourth value. 189 | over4 :: forall a b c d r z. (d -> r) -> T5 a b c d z -> T5 a b c r z 190 | over4 o (a /\ b /\ c /\ d /\ z) = a /\ b /\ c /\ o d /\ z 191 | 192 | -- | Given at least a 5-tuple, modifies the fifth value. 193 | over5 :: forall a b c d e r z. (e -> r) -> T6 a b c d e z -> T6 a b c d r z 194 | over5 o (a /\ b /\ c /\ d /\ e /\ z) = a /\ b /\ c /\ d /\ o e /\ z 195 | 196 | -- | Given at least a 6-tuple, modifies the sixth value. 197 | over6 :: forall a b c d e f r z. (f -> r) -> T7 a b c d e f z -> T7 a b c d e r z 198 | over6 o (a /\ b /\ c /\ d /\ e /\ f /\ z) = a /\ b /\ c /\ d /\ e /\ o f /\ z 199 | 200 | -- | Given at least a 7-tuple, modifies the seventh value. 201 | over7 :: forall a b c d e f g r z. (g -> r) -> T8 a b c d e f g z -> T8 a b c d e f r z 202 | over7 o (a /\ b /\ c /\ d /\ e /\ f /\ g /\ z) = a /\ b /\ c /\ d /\ e /\ f /\ o g /\ z 203 | 204 | -- | Given at least an 8-tuple, modifies the eighth value. 205 | over8 :: forall a b c d e f g h r z. (h -> r) -> T9 a b c d e f g h z -> T9 a b c d e f g r z 206 | over8 o (a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ z) = a /\ b /\ c /\ d /\ e /\ f /\ g /\ o h /\ z 207 | 208 | -- | Given at least a 9-tuple, modifies the ninth value. 209 | over9 :: forall a b c d e f g h i r z. (i -> r) -> T10 a b c d e f g h i z -> T10 a b c d e f g h r z 210 | over9 o (a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ i /\ z) = a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ o i /\ z 211 | 212 | -- | Given at least a 10-tuple, modifies the tenth value. 213 | over10 :: forall a b c d e f g h i j r z. (j -> r) -> T11 a b c d e f g h i j z -> T11 a b c d e f g h i r z 214 | over10 o (a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ i /\ j /\ z) = a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ i /\ o j /\ z 215 | 216 | -- | Given a function of 1 argument, returns a function that accepts a singleton tuple. 217 | uncurry1 :: forall a r z. (a -> r) -> T2 a z -> r 218 | uncurry1 f (a /\ _) = f a 219 | 220 | -- | Given a function of 2 arguments, returns a function that accepts a 2-tuple. 221 | uncurry2 :: forall a b r z. (a -> b -> r) -> T3 a b z -> r 222 | uncurry2 f (a /\ b /\ _) = f a b 223 | 224 | -- | Given a function of 3 arguments, returns a function that accepts a 3-tuple. 225 | uncurry3 :: forall a b c r z. (a -> b -> c -> r) -> T4 a b c z -> r 226 | uncurry3 f (a /\ b /\ c /\ _) = f a b c 227 | 228 | -- | Given a function of 4 arguments, returns a function that accepts a 4-tuple. 229 | uncurry4 :: forall a b c d r z. (a -> b -> c -> d -> r) -> T5 a b c d z -> r 230 | uncurry4 f (a /\ b /\ c /\ d /\ _) = f a b c d 231 | 232 | -- | Given a function of 5 arguments, returns a function that accepts a 5-tuple. 233 | uncurry5 :: forall a b c d e r z. (a -> b -> c -> d -> e -> r) -> T6 a b c d e z -> r 234 | uncurry5 f (a /\ b /\ c /\ d /\ e /\ _) = f a b c d e 235 | 236 | -- | Given a function of 6 arguments, returns a function that accepts a 6-tuple. 237 | uncurry6 :: forall a b c d e f r z. (a -> b -> c -> d -> e -> f -> r) -> T7 a b c d e f z -> r 238 | uncurry6 f' (a /\ b /\ c /\ d /\ e /\ f /\ _) = f' a b c d e f 239 | 240 | -- | Given a function of 7 arguments, returns a function that accepts a 7-tuple. 241 | uncurry7 :: forall a b c d e f g r z. (a -> b -> c -> d -> e -> f -> g -> r) -> T8 a b c d e f g z -> r 242 | uncurry7 f' (a /\ b /\ c /\ d /\ e /\ f /\ g /\ _) = f' a b c d e f g 243 | 244 | -- | Given a function of 8 arguments, returns a function that accepts an 8-tuple. 245 | uncurry8 :: forall a b c d e f g h r z. (a -> b -> c -> d -> e -> f -> g -> h -> r) -> T9 a b c d e f g h z -> r 246 | uncurry8 f' (a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ _) = f' a b c d e f g h 247 | 248 | -- | Given a function of 9 arguments, returns a function that accepts a 9-tuple. 249 | uncurry9 :: forall a b c d e f g h i r z. (a -> b -> c -> d -> e -> f -> g -> h -> i -> r) -> T10 a b c d e f g h i z -> r 250 | uncurry9 f' (a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ i /\ _) = f' a b c d e f g h i 251 | 252 | -- | Given a function of 10 arguments, returns a function that accepts a 10-tuple. 253 | uncurry10 :: forall a b c d e f g h i j r z. (a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> r) -> T11 a b c d e f g h i j z -> r 254 | uncurry10 f' (a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ i /\ j /\ _) = f' a b c d e f g h i j 255 | 256 | -- | Given a function that accepts at least a singleton tuple, returns a function of 1 argument. 257 | curry1 :: forall a r z. z -> (T2 a z -> r) -> a -> r 258 | curry1 z f a = f (a /\ z) 259 | 260 | -- | Given a function that accepts at least a 2-tuple, returns a function of 2 arguments. 261 | curry2 :: forall a b r z. z -> (T3 a b z -> r) -> a -> b -> r 262 | curry2 z f a b = f (a /\ b /\ z) 263 | 264 | -- | Given a function that accepts at least a 3-tuple, returns a function of 3 arguments. 265 | curry3 :: forall a b c r z. z -> (T4 a b c z -> r) -> a -> b -> c -> r 266 | curry3 z f a b c = f (a /\ b /\ c /\ z) 267 | 268 | -- | Given a function that accepts at least a 4-tuple, returns a function of 4 arguments. 269 | curry4 :: forall a b c d r z. z -> (T5 a b c d z -> r) -> a -> b -> c -> d -> r 270 | curry4 z f a b c d = f (a /\ b /\ c /\ d /\ z) 271 | 272 | -- | Given a function that accepts at least a 5-tuple, returns a function of 5 arguments. 273 | curry5 :: forall a b c d e r z. z -> (T6 a b c d e z -> r) -> a -> b -> c -> d -> e -> r 274 | curry5 z f a b c d e = f (a /\ b /\ c /\ d /\ e /\ z) 275 | 276 | -- | Given a function that accepts at least a 6-tuple, returns a function of 6 arguments. 277 | curry6 :: forall a b c d e f r z. z -> (T7 a b c d e f z -> r) -> a -> b -> c -> d -> e -> f -> r 278 | curry6 z f' a b c d e f = f' (a /\ b /\ c /\ d /\ e /\ f /\ z) 279 | 280 | -- | Given a function that accepts at least a 7-tuple, returns a function of 7 arguments. 281 | curry7 :: forall a b c d e f g r z. z -> (T8 a b c d e f g z -> r) -> a -> b -> c -> d -> e -> f -> g -> r 282 | curry7 z f' a b c d e f g = f' (a /\ b /\ c /\ d /\ e /\ f /\ g /\ z) 283 | 284 | -- | Given a function that accepts at least an 8-tuple, returns a function of 8 arguments. 285 | curry8 :: forall a b c d e f g h r z. z -> (T9 a b c d e f g h z -> r) -> a -> b -> c -> d -> e -> f -> g -> h -> r 286 | curry8 z f' a b c d e f g h = f' (a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ z) 287 | 288 | -- | Given a function that accepts at least a 9-tuple, returns a function of 9 arguments. 289 | curry9 :: forall a b c d e f g h i r z. z -> (T10 a b c d e f g h i z -> r) -> a -> b -> c -> d -> e -> f -> g -> h -> i -> r 290 | curry9 z f' a b c d e f g h i = f' (a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ i /\ z) 291 | 292 | -- | Given a function that accepts at least a 10-tuple, returns a function of 10 arguments. 293 | curry10 :: forall a b c d e f g h i j r z. z -> (T11 a b c d e f g h i j z -> r) -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> r 294 | curry10 z f' a b c d e f g h i j = f' (a /\ b /\ c /\ d /\ e /\ f /\ g /\ h /\ i /\ j /\ z) 295 | --------------------------------------------------------------------------------