From e7051443d602540638b27d7060c112bcfb8927aa Mon Sep 17 00:00:00 2001 From: David Chambers Date: Sun, 3 Nov 2019 21:51:40 +0100 Subject: [PATCH] sanctuary-type-identifiers@3.0.0 --- index.js | 26 +++++++++++++------------- package.json | 14 +++++++------- test/index.js | 7 ++----- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 71499fd..717185e 100644 --- a/index.js +++ b/index.js @@ -378,7 +378,10 @@ } var Type$prototype = { - 'constructor': {'@@type': 'sanctuary-def/Type@1'}, + '@@type': 'sanctuary-def/Type@1', + '@@show': function() { + return this.format (I, K (I)); + }, 'validate': function(env) { var test2 = _test (env); var type = this; @@ -408,9 +411,6 @@ Z.equals (this.keys, other.keys) && Z.equals (this.types, other.types) ); - }, - '@@show': function() { - return this.format (I, K (I)); } }; @@ -1604,30 +1604,30 @@ //. const show = require ('sanctuary-show'); //. const type = require ('sanctuary-type-identifiers'); //. - //. // MaybeTypeRep :: TypeRep Maybe - //. const MaybeTypeRep = {'@@type': 'my-package/Maybe'}; + //. // maybeTypeIdent :: String + //. const maybeTypeIdent = 'my-package/Maybe'; //. //. // Maybe :: Type -> Type //. const Maybe = $.UnaryType //. ('Maybe') //. ('http://example.com/my-package#Maybe') //. ([]) - //. (x => type (x) === MaybeTypeRep['@@type']) + //. (x => type (x) === maybeTypeIdent) //. (maybe => maybe.isJust ? [maybe.value] : []); //. //. // Nothing :: Maybe a //. const Nothing = { - //. 'constructor': MaybeTypeRep, //. 'isJust': false, //. 'isNothing': true, + //. '@@type': maybeTypeIdent, //. '@@show': () => 'Nothing', //. }; //. //. // Just :: a -> Maybe a //. const Just = x => ({ - //. 'constructor': MaybeTypeRep, //. 'isJust': true, //. 'isNothing': false, + //. '@@type': maybeTypeIdent, //. '@@show': () => `Just (${show (x)})`, //. 'value': x, //. }); @@ -1720,15 +1720,15 @@ //. ```javascript //. const type = require ('sanctuary-type-identifiers'); //. - //. // PairTypeRep :: TypeRep Pair - //. const PairTypeRep = {'@@type': 'my-package/Pair'}; + //. // pairTypeIdent :: String + //. const pairTypeIdent = 'my-package/Pair'; //. //. // $Pair :: Type -> Type -> Type //. const $Pair = $.BinaryType //. ('Pair') //. ('http://example.com/my-package#Pair') //. ([]) - //. (x => type (x) === PairTypeRep['@@type']) + //. (x => type (x) === pairTypeIdent) //. (({fst}) => [fst]) //. (({snd}) => [snd]); //. @@ -1738,9 +1738,9 @@ //. ({}) //. ([a, b, $Pair (a) (b)]) //. (fst => snd => ({ - //. 'constructor': PairTypeRep, //. 'fst': fst, //. 'snd': snd, + //. '@@type': pairTypeIdent, //. '@@show': () => `Pair (${show (fst)}) (${show (snd)})`, //. })); //. diff --git a/package.json b/package.json index 7972a88..7111955 100644 --- a/package.json +++ b/package.json @@ -14,16 +14,16 @@ "test": "npm run lint && sanctuary-test && npm run doctest" }, "dependencies": { - "sanctuary-either": "1.2.0", + "sanctuary-either": "2.0.0", "sanctuary-show": "2.0.0", - "sanctuary-type-classes": "11.0.x", - "sanctuary-type-identifiers": "2.0.x" + "sanctuary-type-classes": "12.0.0", + "sanctuary-type-identifiers": "3.0.0" }, "devDependencies": { - "sanctuary-descending": "1.2.0", - "sanctuary-identity": "1.2.0", - "sanctuary-maybe": "1.2.0", - "sanctuary-pair": "1.2.0", + "sanctuary-descending": "2.0.0", + "sanctuary-identity": "2.0.0", + "sanctuary-maybe": "2.0.0", + "sanctuary-pair": "2.0.0", "sanctuary-scripts": "4.0.x" }, "files": [ diff --git a/test/index.js b/test/index.js index 75d958c..1f262de 100644 --- a/test/index.js +++ b/test/index.js @@ -1431,13 +1431,10 @@ Since there is no type of which all the above values are members, the type-varia eq ($.AnyFunction.url) (`https://github.com/sanctuary-js/sanctuary-def/tree/v${version}#Function`); eq ($.AnyFunction.supertypes) ([]); - function Identity(x) { this.value = x; } - Identity['@@type'] = 'my-package/Identity'; - const isAnyFunction = $.test ([]) ($.AnyFunction); eq (isAnyFunction (null)) (false); eq (isAnyFunction (Math.abs)) (true); - eq (isAnyFunction (Identity)) (true); + eq (isAnyFunction (function Identity(x) { this.value = x; })) (true); eq (isAnyFunction (function* (x) { return x; })) (true); }); @@ -3084,8 +3081,8 @@ See https://github.com/sanctuary-js/sanctuary-type-classes/tree/v${Z$version}#Al test ('supports unary type variables', () => { // Box :: a -> Box a const Box = x => ({ - 'constructor': {'@@type': 'my-package/Box@1'}, 'value': x, + '@@type': 'my-package/Box@1', '@@show': () => 'Box (' + show (x) + ')', });