Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct type of $.test #121

Closed
wants to merge 1 commit into from
Closed

Correct type of $.test #121

wants to merge 1 commit into from

Conversation

Avaq
Copy link
Member

@Avaq Avaq commented Feb 23, 2017

Opened the WIP pull-request for discussion. Comments will follow.

Copy link
Member Author

@Avaq Avaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some points of discussion

index.js Outdated
@@ -2405,7 +2416,7 @@
Date: Date_,
Error: Error_,
FiniteNumber: FiniteNumber,
Function: def('Function', {}, [Array_(Type), Type], Function_),
Function: def('Function', {}, [Array_(VariadicType), Type], Function_),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this one, but I'm not sure that I should. I'll ask you first. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should remain unchanged. It doesn't make sense to define Array -> Array or Either -> Either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Avaq Avaq force-pushed the avaq/correct-typeof-test branch from e182592 to ae60bce Compare February 23, 2017 12:48
'sanctuary-def/VariadicType',
'',
function(x) {
return test([], Type, x) || test([], AnyFunction, x);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried different ways of testing:

  1. test([], Type, applyParameterizedType(x)) - This blows up if someone would provide, say [x => true] as env.
  2. test([], Type, x) || test([], Function([Type, Type]), x) || test([], Function([Type, Type, Type]), x) - This effectively behaves the same as AnyFunction, because test does not apply x to determine its types.
  3. This left me with the method seen above.

The decision, really, is between 1 and 3, where 3 is overly permissive, and 1 blows up with an ugly error. Maybe to get the best of both worlds, I should combine them as:

test([], Type, x) || test([], AnyFunction, x) && test([], Type, applyParameterizedType(x))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This predicate looks fine to me. I think the ultimate solution is to require values such as $.Array($.Unknown) and S.EitherType($.Unknown, $.Unknown) in place of $.Array and S.EitherType. I hope VariadicType will be short-lived, so the predicate need not be perfect.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you vote for not combining 1 and 3? In that case, shall I undo the diff that introduces applyParameterizedType (singular)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.js Outdated
type.apply(null, Z.map(K(Unknown), range(0, type.length))) :
type;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the reason for this diff in my other comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to include this refactoring to keep the diff as clear as possible. If you explained your reasons for making this its own function in another comment, I haven't been able to find the comment. ;)

Copy link
Member Author

@Avaq Avaq Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason was to enable the test([], Type, applyParameterizedType(x))-way of testing VariadicType membership. I left it in for illustrative purposes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. I didn't make the connection, I'm sorry.

@Avaq Avaq force-pushed the avaq/correct-typeof-test branch 2 times, most recently from b10964e to 62754fc Compare February 23, 2017 14:10
@Avaq Avaq changed the title WIP: Correct type of $.test Correct type of $.test Feb 23, 2017
@Avaq
Copy link
Member Author

Avaq commented Feb 23, 2017

🍏

index.js Outdated
@@ -762,6 +762,14 @@
typeEq('sanctuary-def/Type')
);

var VariadicType = NullaryType(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a type signature along these lines:

//  VariadicType :: Type | Type -> Type | Type -> Type -> Type | ...

The made-up nature of the signature will draw attention to our naughtiness.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Avaq Avaq force-pushed the avaq/correct-typeof-test branch from 62754fc to 043d176 Compare February 23, 2017 14:34
@davidchambers
Copy link
Member

I'll close this in accordance with #123 (comment).

@davidchambers davidchambers deleted the avaq/correct-typeof-test branch February 26, 2017 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants