Skip to content

Commit

Permalink
Correct the type of $.test
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Feb 23, 2017
1 parent 40a8cd5 commit 62754fc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,14 @@
typeEq('sanctuary-def/Type')
);

var VariadicType = NullaryType(
'sanctuary-def/VariadicType',
'',
function(x) {
return test([], Type, x) || test([], AnyFunction, x);
}
);

// TypeClass :: Type
var TypeClass = NullaryType(
'sanctuary-type-classes/TypeClass',
Expand Down Expand Up @@ -2433,7 +2441,7 @@
ValidNumber: ValidNumber,
env: env,
create: create,
test: def('test', {}, [Array_(Type), Type, Any, Boolean_], test),
test: def('test', {}, [Array_(VariadicType), Type, Any, Boolean_], test),
NullaryType: CheckedNullaryType,
UnaryType: CheckedUnaryType,
BinaryType: CheckedBinaryType,
Expand Down
14 changes: 13 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2862,7 +2862,7 @@ describe('test', function() {
it('is a ternary function', function() {
eq(typeof $.test, 'function');
eq($.test.length, 3);
eq($.test.toString(), 'test :: Array Type -> Type -> Any -> Boolean');
eq($.test.toString(), 'test :: Array VariadicType -> Type -> Any -> Boolean');
});

it('supports nullary types', function() {
Expand Down Expand Up @@ -2904,6 +2904,18 @@ describe('test', function() {
eq($.test($.env, $Pair(a, b), Pair('foo', 42)), true);
});

it('supports environments with unary types', function() {
eq($.test($.env.concat([$.Array]), $.Array(a), null), false);
eq($.test($.env.concat([$.Array]), $.Array(a), [1]), true);
eq($.test($.env.concat([$.Array]), $.Array(a), [[]]), true);
});

it('supports environments with binary types', function() {
eq($.test($.env.concat([$Pair]), $Pair(a, b), null), false);
eq($.test($.env.concat([$Pair]), $Pair(a, b), Pair(1, '2')), true);
eq($.test($.env.concat([$Pair]), $Pair(a, b), Pair(Pair(1, '2'), Pair(1, '2'))), true);
});

});

describe('NullaryType', function() {
Expand Down

0 comments on commit 62754fc

Please sign in to comment.