Skip to content

Commit

Permalink
Merge pull request #285 from sanctuary-js/davidchambers/type-idents
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers authored Jan 18, 2020
2 parents 6e0e93e + e705144 commit e2d4620
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
26 changes: 13 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -408,9 +411,6 @@
Z.equals (this.keys, other.keys) &&
Z.equals (this.types, other.types)
);
},
'@@show': function() {
return this.format (I, K (I));
}
};

Expand Down Expand Up @@ -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,
//. });
Expand Down Expand Up @@ -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]);
//.
Expand All @@ -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)})`,
//. }));
//.
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
7 changes: 2 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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) + ')',
});

Expand Down

0 comments on commit e2d4620

Please sign in to comment.