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

bring your own environment #188

Closed
davidchambers opened this issue Apr 22, 2016 · 0 comments
Closed

bring your own environment #188

davidchambers opened this issue Apr 22, 2016 · 0 comments

Comments

@davidchambers
Copy link
Member

Problem:

S.I(['foo', 42]);
// ! TypeError: Type-variable constraint violation
//
//   I :: a -> a
//        ^
//        1
//
//   1)  ["foo", 42] :: Array ???
//
//   Since there is no type of which all the above values are members, the type-variable constraint has been violated.

If this is a case of array-as-list, a type error is appropriate. But perhaps it's a case of array-as-tuple?

sanctuary-def could—and should—provide Pair a b to support two-element arrays. The fact remains, though, that Sanctuary's environment cannot possibly include every type, as there are infinitely many.

Solution:

The user must have the ability to provide her own environment.

"Initializing" Sanctuary is currently done in one of two ways:

const S = require('sanctuary');
const S = require('sanctuary').unchecked;

If the user is to provide an environment, it makes sense to take (checkTypes :: Boolean, env :: [Type]) as $.create does:

const sanctuary = require('sanctuary');

const S = sanctuary.create(true, sanctuary.env);
const sanctuary = require('sanctuary');

const S = sanctuary.create(false, sanctuary.env);

When @Avaq and I discussed this on Gitter, he suggested having const S = require('sanctuary'); continue to work as it does today. This strikes me as a great idea, as it would allow new users to have a positive first experience with the library.

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

No branches or pull requests

1 participant