├── .envrc ├── .gitignore ├── LICENSE ├── README.md ├── bower.json ├── nix ├── easy-ps.nix └── pinned.nix ├── package.json ├── packages.dhall ├── shell.nix ├── spago.dhall ├── src └── Data │ └── Tuple │ ├── Native.js │ └── Native.purs └── test ├── Main.js └── Main.purs /.envrc: -------------------------------------------------------------------------------- 1 | use_nix 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /generated-docs/ 6 | /.psc* 7 | /.purs* 8 | /.psa* 9 | /.spago/ 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, 2016, 2017, 2018, 2019, 2020 Athan Clark 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following 13 | disclaimer in the documentation and/or other materials provided 14 | with the distribution. 15 | 16 | * Neither the name of Athan Clark nor the names of other 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # purescript-tuples-native 2 | 3 | This library defines tuple data types that are represented under-the-hood as heterogeneous arrays to JavaScript - useful for 4 | foreign interfaces. A set of `xt` functions are exposed to translate these native Tuples into Purescript pairs 5 | or Nested tuples. So for example: 6 | 7 | ```purescript 8 | -- Main.purs 9 | import Data.Tuple.Native (T2, xt) 10 | import Data.Tuple (Tuple) 11 | 12 | foreign import lenTupleImpl :: String -> T2 String Int 13 | 14 | lenTuple :: String -> Tuple String Int 15 | lenTuple s = xt $ lenTupleImpl s 16 | ``` 17 | 18 | Could let you wrap this Javascript function 19 | ```javascript 20 | "use strict"; 21 | function lenTuple (string) { 22 | return [string, string.length] 23 | } 24 | exports.lenTupleImpl = lenTuple 25 | ``` 26 | 27 | You can also extract indidual elements directly from the Native tuple using `prj`. 28 | 29 | ```purescript 30 | import Data.Tuple.Native (T3, t3, prj) 31 | import Data.TypeLevel.Num.Reps (d0, d1, d2) 32 | 33 | xs :: T3 String Int Boolean 34 | xs = t3 "foo" 13 false 35 | 36 | prj d0 xs == "foo" -- true 37 | prj d1 xs == 13 -- true 38 | prj d2 xs == false -- true 39 | ``` 40 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "purescript-tuples-native", 3 | "ignore": [ 4 | "**/.*", 5 | "node_modules", 6 | "bower_components", 7 | "output" 8 | ], 9 | "license": "BSD-3-Clause", 10 | "repository": { 11 | "url": "https://github.com/athanclark/purescript-tuples-native.git", 12 | "type": "git" 13 | }, 14 | "dependencies": { 15 | "purescript-prelude": "^4.1.1", 16 | "purescript-unsafe-coerce": "^4.0.0", 17 | "purescript-typelevel": "^6.0.0", 18 | }, 19 | "devDependencies": { 20 | "purescript-psci-support": "^4.0.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /nix/easy-ps.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import ./pinned.nix { } }: 2 | 3 | import 4 | ( 5 | pkgs.fetchFromGitHub { 6 | owner = "justinwoo"; 7 | repo = "easy-purescript-nix"; 8 | rev = "master"; 9 | sha256 = "03g9xq451dmrkq8kiz989wnl8k0lmj60ajflz44bhp7cm08hf3bw"; 10 | } 11 | ) { 12 | inherit pkgs; 13 | } 14 | -------------------------------------------------------------------------------- /nix/pinned.nix: -------------------------------------------------------------------------------- 1 | import ( 2 | builtins.fetchTarball { 3 | url = "https://github.com/NixOS/nixpkgs/archive/21.11.tar.gz"; 4 | sha256 = "162dywda2dvfj1248afxc45kcrg83appjd0nmdb541hl7rnncf02"; 5 | } 6 | ) 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "spago": "^0.20.9" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages.dhall: -------------------------------------------------------------------------------- 1 | let upstream = 2 | https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20220901/packages.dhall sha256:f1531b29c21ac437ffe5666c1b6cc76f0a9c29d3c9d107ff047aa2567744994f 3 | 4 | let overrides = {=} 5 | 6 | let additions = {=} 7 | 8 | in upstream // overrides // additions 9 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import ./nix/pinned.nix { } }: 2 | let 3 | easy-ps = import ./nix/easy-ps.nix { inherit pkgs; }; 4 | 5 | build = pkgs.writeShellScriptBin "build" '' 6 | #!/usr/bin/env bash 7 | purs compile "src/**/*.purs" "test/**/*.purs" 8 | ''; 9 | in 10 | pkgs.mkShell { 11 | name = "purescript-reactix-d3"; 12 | 13 | buildInputs = [ 14 | easy-ps.purs-0_15_4 15 | easy-ps.psc-package 16 | build 17 | pkgs.dhall-json 18 | ]; 19 | } 20 | -------------------------------------------------------------------------------- /spago.dhall: -------------------------------------------------------------------------------- 1 | {- 2 | Welcome to a Spago project! 3 | You can edit this file as you like. 4 | -} 5 | { name = "tuples-native" 6 | , dependencies = 7 | [ "console" 8 | , "effect" 9 | , "functions" 10 | , "prelude" 11 | , "tuples" 12 | , "typelevel" 13 | , "typelevel-prelude" 14 | ] 15 | , packages = ./packages.dhall 16 | , sources = [ "src/**/*.purs", "test/**/*.purs" ] 17 | } 18 | -------------------------------------------------------------------------------- /src/Data/Tuple/Native.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | export function prjImpl(n, t) { 4 | return t[n]; 5 | }; 6 | 7 | export function t2_ (a, b) { 8 | return [a,b]; 9 | }; 10 | 11 | export function t3_ (a,b,c) { 12 | return [a,b,c]; 13 | }; 14 | 15 | export function t4_ (a,b,c,d) { 16 | return [a,b,c,d]; 17 | }; 18 | 19 | export function t5_ (a,b,c,d,e) { 20 | return [a,b,c,d,e]; 21 | }; 22 | 23 | export function t6_ (a,b,c,d,e,f) { 24 | return [a,b,c,d,e,f]; 25 | }; 26 | 27 | export function t7_ (a,b,c,d,e,f,g) { 28 | return [a,b,c,d,e,f,g]; 29 | }; 30 | 31 | export function t8_ (a,b,c,d,e,f,g,h) { 32 | return [a,b,c,d,e,f,g,h]; 33 | }; 34 | 35 | export function t9_ (a,b,c,d,e,f,g,h,i) { 36 | return [a,b,c,d,e,f,g,h,i]; 37 | }; 38 | -------------------------------------------------------------------------------- /src/Data/Tuple/Native.purs: -------------------------------------------------------------------------------- 1 | -- | Heterogeneous arrays for foreign function interfaces. 2 | 3 | module Data.Tuple.Native 4 | ( TupleN 5 | , T2, T3, T4, T5, T6, T7, T8, T9 6 | , t2, t3, t4, t5, t6, t7, t8, t9 7 | , t2_, t3_, t4_, t5_, t6_, t7_, t8_, t9_ 8 | , xt 9 | , xt2, xt3, xt4, xt5, xt6, xt7, xt8, xt9 10 | , prj 11 | , class TupleSize, class ShowNat 12 | ) where 13 | 14 | import Data.Function.Uncurried (Fn2, Fn3, Fn4, Fn5, Fn6, Fn7, Fn8, Fn9, runFn2, runFn3, runFn4, runFn5, runFn6, runFn7, runFn8, runFn9) 15 | import Data.Generic.Rep (class Generic, Constructor(..), Argument(..), Product(..)) 16 | import Data.Tuple as DT 17 | import Data.Tuple.Nested as DTN 18 | import Data.Typelevel.Num (D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, class Lt, class Nat, toInt, d0, d1, d2, d3, d4, d5, d6, d7, d8) 19 | import Prelude (($)) 20 | import Prim.Row (class Cons) 21 | import Prim.RowList (RowList) 22 | import Type.RowList (Cons, Nil, class ListToRow) 23 | 24 | -- | Safely coerce a `TupleN` pair into a PureScript Tuple 25 | xt :: forall a b. T2 a b -> DT.Tuple a b 26 | xt t = DT.Tuple (prj d0 t) (prj d1 t) 27 | 28 | -- | Safely coerce a `TupleN` pair into a PureScript Nested Tuple 29 | xt2 :: forall a b. T2 a b -> DTN.Tuple2 a b 30 | xt2 t = DTN.tuple2 (prj d0 t) (prj d1 t) 31 | 32 | xt3 :: forall a b c. T3 a b c -> DTN.Tuple3 a b c 33 | xt3 t = DTN.tuple3 (prj d0 t) (prj d1 t) (prj d2 t) 34 | 35 | xt4 :: forall a b c d. T4 a b c d -> DTN.Tuple4 a b c d 36 | xt4 t = DTN.tuple4 (prj d0 t) (prj d1 t) (prj d2 t) (prj d3 t) 37 | 38 | xt5 :: forall a b c d e. T5 a b c d e -> DTN.Tuple5 a b c d e 39 | xt5 t = DTN.tuple5 (prj d0 t) (prj d1 t) (prj d2 t) (prj d3 t) (prj d4 t) 40 | 41 | xt6 :: forall a b c d e f. T6 a b c d e f -> DTN.Tuple6 a b c d e f 42 | xt6 t = DTN.tuple6 (prj d0 t) (prj d1 t) (prj d2 t) (prj d3 t) (prj d4 t) (prj d5 t) 43 | 44 | xt7 :: forall a b c d e f g. T7 a b c d e f g -> DTN.Tuple7 a b c d e f g 45 | xt7 t = DTN.tuple7 (prj d0 t) (prj d1 t) (prj d2 t) (prj d3 t) (prj d4 t) (prj d5 t) (prj d6 t) 46 | 47 | xt8 :: forall a b c d e f g h. T8 a b c d e f g h -> DTN.Tuple8 a b c d e f g h 48 | xt8 t = DTN.tuple8 (prj d0 t) (prj d1 t) (prj d2 t) (prj d3 t) (prj d4 t) (prj d5 t) (prj d6 t) (prj d7 t) 49 | 50 | xt9 :: forall a b c d e f g h i. T9 a b c d e f g h i -> DTN.Tuple9 a b c d e f g h i 51 | xt9 t = DTN.tuple9 (prj d0 t) (prj d1 t) (prj d2 t) (prj d3 t) (prj d4 t) (prj d5 t) (prj d6 t) (prj d7 t) (prj d8 t) 52 | 53 | foreign import prjImpl :: forall t a. Fn2 Int (TupleN t) a 54 | 55 | -- | Project a value of index `n` from a `TupleN`, using `Data.TypeLevel.Num.Reps.dN` as Nat values. 56 | prj :: forall t t' t'' n n' a size 57 | . TupleSize size t 58 | => Lt n size 59 | => ShowNat n n' 60 | => ListToRow t t' 61 | => Cons n' a t'' t' 62 | => Nat n 63 | => n -> TupleN t -> a 64 | prj n t = runFn2 prjImpl (toInt n) t 65 | 66 | 67 | 68 | -- | Represented as a heterogeneous array under the hood 69 | foreign import data TupleN :: RowList Type -> Type 70 | 71 | 72 | type T2 a b = 73 | TupleN (Cons "0" a (Cons "1" b Nil)) 74 | type T3 a b c = 75 | TupleN (Cons "0" a (Cons "1" b (Cons "2" c Nil))) 76 | type T4 a b c d = 77 | TupleN (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d Nil)))) 78 | type T5 a b c d e = 79 | TupleN (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e Nil))))) 80 | type T6 a b c d e f = 81 | TupleN (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e (Cons "5" f Nil)))))) 82 | type T7 a b c d e f g = 83 | TupleN (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e (Cons "5" f (Cons "6" g Nil))))))) 84 | type T8 a b c d e f g h = 85 | TupleN (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e (Cons "5" f (Cons "6" g (Cons "7" h Nil)))))))) 86 | type T9 a b c d e f g h i = 87 | TupleN (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e (Cons "5" f (Cons "6" g (Cons "7" h (Cons "8" i Nil))))))))) 88 | 89 | 90 | t2 :: forall a b . a -> b -> T2 a b 91 | t2 = runFn2 t2_ 92 | t3 :: forall a b c . a -> b -> c -> (T3 a b c) 93 | t3 = runFn3 t3_ 94 | t4 :: forall a b c d . a -> b -> c -> d -> (T4 a b c d) 95 | t4 = runFn4 t4_ 96 | t5 :: forall a b c d e . a -> b -> c -> d -> e -> (T5 a b c d e) 97 | t5 = runFn5 t5_ 98 | t6 :: forall a b c d e f . a -> b -> c -> d -> e -> f -> (T6 a b c d e f) 99 | t6 = runFn6 t6_ 100 | t7 :: forall a b c d e f g . a -> b -> c -> d -> e -> f -> g -> (T7 a b c d e f g) 101 | t7 = runFn7 t7_ 102 | t8 :: forall a b c d e f g h . a -> b -> c -> d -> e -> f -> g -> h -> (T8 a b c d e f g h) 103 | t8 = runFn8 t8_ 104 | t9 :: forall a b c d e f g h i. a -> b -> c -> d -> e -> f -> g -> h -> i -> (T9 a b c d e f g h i) 105 | t9 = runFn9 t9_ 106 | 107 | foreign import t2_ :: forall a b . Fn2 a b (T2 a b) 108 | foreign import t3_ :: forall a b c . Fn3 a b c (T3 a b c) 109 | foreign import t4_ :: forall a b c d . Fn4 a b c d (T4 a b c d) 110 | foreign import t5_ :: forall a b c d e . Fn5 a b c d e (T5 a b c d e) 111 | foreign import t6_ :: forall a b c d e f . Fn6 a b c d e f (T6 a b c d e f) 112 | foreign import t7_ :: forall a b c d e f g . Fn7 a b c d e f g (T7 a b c d e f g) 113 | foreign import t8_ :: forall a b c d e f g h . Fn8 a b c d e f g h (T8 a b c d e f g h) 114 | foreign import t9_ :: forall a b c d e f g h i. Fn9 a b c d e f g h i (T9 a b c d e f g h i) 115 | 116 | class TupleSize n (t :: RowList Type) | t -> n 117 | 118 | instance tupleSizeT2 :: TupleSize D2 (Cons "0" a (Cons "1" b Nil)) 119 | instance tupleSizeT3 :: TupleSize D3 (Cons "0" a (Cons "1" b (Cons "2" c Nil))) 120 | instance tupleSizeT4 :: TupleSize D4 (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d Nil)))) 121 | instance tupleSizeT5 :: TupleSize D5 (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e Nil))))) 122 | instance tupleSizeT6 :: TupleSize D6 (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e (Cons "5" f Nil)))))) 123 | instance tupleSizeT7 :: TupleSize D7 (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e (Cons "5" f (Cons "6" g Nil))))))) 124 | instance tupleSizeT8 :: TupleSize D8 (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e (Cons "5" f (Cons "6" g (Cons "7" h Nil)))))))) 125 | instance tupleSizeT9 :: TupleSize D9 (Cons "0" a (Cons "1" b (Cons "2" c (Cons "3" d (Cons "4" e (Cons "5" f (Cons "6" g (Cons "7" h (Cons "8" i Nil))))))))) 126 | 127 | 128 | instance genericTuple2 :: Generic 129 | (TupleN (Cons "0" a (Cons "1" b Nil))) 130 | (Constructor "t2" (Product (Argument a) (Argument b))) where 131 | to (Constructor (Product (Argument a) (Argument b))) = runFn2 t2_ a b 132 | from xs = Constructor (Product (Argument (prj d0 xs)) (Argument (prj d1 xs))) 133 | 134 | instance genericTuple3 :: Generic 135 | (TupleN (Cons "0" a (Cons "1" b (Cons "2" c Nil)))) 136 | (Constructor "t3" (Product (Argument a) (Product (Argument b) (Argument c)))) where 137 | to (Constructor (Product (Argument a) (Product (Argument b) (Argument c)))) = runFn3 t3_ a b c 138 | from xs = Constructor $ Product (Argument (prj d0 xs)) $ Product (Argument (prj d1 xs)) (Argument (prj d2 xs)) 139 | 140 | instance genericTuple4 :: Generic 141 | (TupleN (Cons "0" a 142 | (Cons "1" b 143 | (Cons "2" c 144 | (Cons "3" d Nil))))) 145 | (Constructor "t4" (Product (Argument a) 146 | (Product (Argument b) 147 | (Product (Argument c) 148 | (Argument d))))) where 149 | to (Constructor (Product (Argument a) 150 | (Product (Argument b) 151 | (Product (Argument c) 152 | (Argument d))))) = runFn4 t4_ a b c d 153 | from xs = Constructor $ Product (Argument (prj d0 xs)) 154 | $ Product (Argument (prj d1 xs)) 155 | $ Product (Argument (prj d2 xs)) 156 | (Argument (prj d3 xs)) 157 | 158 | instance genericTuple5 :: Generic 159 | (TupleN (Cons "0" a 160 | (Cons "1" b 161 | (Cons "2" c 162 | (Cons "3" d 163 | (Cons "4" e Nil)))))) 164 | (Constructor "t5" (Product (Argument a) 165 | (Product (Argument b) 166 | (Product (Argument c) 167 | (Product (Argument d) 168 | (Argument e)))))) where 169 | to (Constructor (Product (Argument a) 170 | (Product (Argument b) 171 | (Product (Argument c) 172 | (Product (Argument d) 173 | (Argument e)))))) = runFn5 t5_ a b c d e 174 | from xs = Constructor $ Product (Argument (prj d0 xs)) 175 | $ Product (Argument (prj d1 xs)) 176 | $ Product (Argument (prj d2 xs)) 177 | $ Product (Argument (prj d3 xs)) 178 | (Argument (prj d4 xs)) 179 | 180 | instance genericTuple6 :: Generic 181 | (TupleN (Cons "0" a 182 | (Cons "1" b 183 | (Cons "2" c 184 | (Cons "3" d 185 | (Cons "4" e 186 | (Cons "5" f Nil))))))) 187 | (Constructor "t6" (Product (Argument a) 188 | (Product (Argument b) 189 | (Product (Argument c) 190 | (Product (Argument d) 191 | (Product (Argument e) 192 | (Argument f))))))) where 193 | to (Constructor (Product (Argument a) 194 | (Product (Argument b) 195 | (Product (Argument c) 196 | (Product (Argument d) 197 | (Product (Argument e) 198 | (Argument f))))))) = runFn6 t6_ a b c d e f 199 | from xs = Constructor $ Product (Argument (prj d0 xs)) 200 | $ Product (Argument (prj d1 xs)) 201 | $ Product (Argument (prj d2 xs)) 202 | $ Product (Argument (prj d3 xs)) 203 | $ Product (Argument (prj d4 xs)) 204 | (Argument (prj d5 xs)) 205 | 206 | instance genericTuple7 :: Generic 207 | (TupleN (Cons "0" a 208 | (Cons "1" b 209 | (Cons "2" c 210 | (Cons "3" d 211 | (Cons "4" e 212 | (Cons "5" f 213 | (Cons "6" g Nil)))))))) 214 | (Constructor "t7" (Product (Argument a) 215 | (Product (Argument b) 216 | (Product (Argument c) 217 | (Product (Argument d) 218 | (Product (Argument e) 219 | (Product (Argument f) 220 | (Argument g)))))))) where 221 | to (Constructor (Product (Argument a) 222 | (Product (Argument b) 223 | (Product (Argument c) 224 | (Product (Argument d) 225 | (Product (Argument e) 226 | (Product (Argument f) 227 | (Argument g)))))))) = runFn7 t7_ a b c d e f g 228 | from xs = Constructor $ Product (Argument (prj d0 xs)) 229 | $ Product (Argument (prj d1 xs)) 230 | $ Product (Argument (prj d2 xs)) 231 | $ Product (Argument (prj d3 xs)) 232 | $ Product (Argument (prj d4 xs)) 233 | $ Product (Argument (prj d5 xs)) 234 | (Argument (prj d6 xs)) 235 | 236 | instance genericTuple8 :: Generic 237 | (TupleN (Cons "0" a 238 | (Cons "1" b 239 | (Cons "2" c 240 | (Cons "3" d 241 | (Cons "4" e 242 | (Cons "5" f 243 | (Cons "6" g 244 | (Cons "7" h Nil))))))))) 245 | (Constructor "t8" (Product (Argument a) 246 | (Product (Argument b) 247 | (Product (Argument c) 248 | (Product (Argument d) 249 | (Product (Argument e) 250 | (Product (Argument f) 251 | (Product (Argument g) 252 | (Argument h))))))))) where 253 | to (Constructor (Product (Argument a) 254 | (Product (Argument b) 255 | (Product (Argument c) 256 | (Product (Argument d) 257 | (Product (Argument e) 258 | (Product (Argument f) 259 | (Product (Argument g) 260 | (Argument h))))))))) = runFn8 t8_ a b c d e f g h 261 | from xs = Constructor $ Product (Argument (prj d0 xs)) 262 | $ Product (Argument (prj d1 xs)) 263 | $ Product (Argument (prj d2 xs)) 264 | $ Product (Argument (prj d3 xs)) 265 | $ Product (Argument (prj d4 xs)) 266 | $ Product (Argument (prj d5 xs)) 267 | $ Product (Argument (prj d6 xs)) 268 | (Argument (prj d7 xs)) 269 | 270 | instance genericTuple9 :: Generic 271 | (TupleN (Cons "0" a 272 | (Cons "1" b 273 | (Cons "2" c 274 | (Cons "3" d 275 | (Cons "4" e 276 | (Cons "5" f 277 | (Cons "6" g 278 | (Cons "7" h 279 | (Cons "8" i Nil)))))))))) 280 | (Constructor "t9" (Product (Argument a) 281 | (Product (Argument b) 282 | (Product (Argument c) 283 | (Product (Argument d) 284 | (Product (Argument e) 285 | (Product (Argument f) 286 | (Product (Argument g) 287 | (Product (Argument h) 288 | (Argument i)))))))))) where 289 | to (Constructor (Product (Argument a) 290 | (Product (Argument b) 291 | (Product (Argument c) 292 | (Product (Argument d) 293 | (Product (Argument e) 294 | (Product (Argument f) 295 | (Product (Argument g) 296 | (Product (Argument h) 297 | (Argument i)))))))))) = runFn9 t9_ a b c d e f g h i 298 | from xs = Constructor $ Product (Argument (prj d0 xs)) 299 | $ Product (Argument (prj d1 xs)) 300 | $ Product (Argument (prj d2 xs)) 301 | $ Product (Argument (prj d3 xs)) 302 | $ Product (Argument (prj d4 xs)) 303 | $ Product (Argument (prj d5 xs)) 304 | $ Product (Argument (prj d6 xs)) 305 | $ Product (Argument (prj d7 xs)) 306 | (Argument (prj d8 xs)) 307 | 308 | 309 | class ShowNat n (s :: Symbol) | n -> s, s -> n 310 | 311 | instance showNatD0 :: ShowNat D0 "0" 312 | instance showNatD1 :: ShowNat D1 "1" 313 | instance showNatD2 :: ShowNat D2 "2" 314 | instance showNatD3 :: ShowNat D3 "3" 315 | instance showNatD4 :: ShowNat D4 "4" 316 | instance showNatD5 :: ShowNat D5 "5" 317 | instance showNatD6 :: ShowNat D6 "6" 318 | instance showNatD7 :: ShowNat D7 "7" 319 | instance showNatD8 :: ShowNat D8 "8" 320 | -------------------------------------------------------------------------------- /test/Main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | export function lenTupleImpl (string) { 4 | return [string, string.length] 5 | } 6 | -------------------------------------------------------------------------------- /test/Main.purs: -------------------------------------------------------------------------------- 1 | module Test.Main where 2 | 3 | import Data.Tuple.Native (T2, T3, prj, t3, xt, xt3) 4 | import Data.Tuple (Tuple) 5 | import Data.Tuple.Nested (Tuple3) 6 | import Data.Typelevel.Num (d0, d1, d2) 7 | 8 | import Prelude (Unit, discard, ($)) 9 | import Effect (Effect) 10 | import Effect.Console (logShow) 11 | 12 | foreign import lenTupleImpl :: String -> T2 String Int 13 | 14 | lenTuple :: String -> Tuple String Int 15 | lenTuple s = xt $ lenTupleImpl s 16 | 17 | main :: Effect Unit 18 | main = do 19 | let x :: T3 Int Int Int 20 | x = t3 1 2 3 21 | 22 | logShow $ prj d0 x 23 | logShow $ prj d1 x 24 | logShow $ prj d2 x 25 | 26 | let t :: Tuple3 Int Int Int 27 | t = xt3 x 28 | logShow $ t 29 | 30 | -- test foreign import 31 | let l :: Tuple String Int 32 | l = lenTuple "Testing" 33 | logShow l 34 | --------------------------------------------------------------------------------