-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
ADTs defined using S functions are compatible only with types known to S #262
Comments
Another option would be to use |
Using
|
This is a perfectly reasonable decision to make at the application level. An algebraic data type, though, should be usable in applications which do not use Sanctuary (in addition to those which do). Were I to use several FL-compatible ADTs in an application I would expect them to work together without first introducing them to one another. This suggests to me that methods of ADTs should not perform type checking.
We could certainly change the type from create :: { checkTypes :: Boolean, env :: Array Type } -> Module to create :: Maybe (Array Type) -> Module which is undoubtedly more elegant. It may be less convenient, though: -const S = create({
- checkTypes: process.env.NODE_ENV !== 'production',
- env: env.concat([IdentityType]),
-});
+const S = create(process.env.NODE_ENV === 'production' ?
+ Nothing :
+ Just(env.concat([IdentityType])));
Prior to #206 we supported
I don't think we considered this API. We decided the behaviour of I'm happy to reconsider the API.
This option scares me, I must admit. 😜 |
I see your point. That's rather painful. Disabling type-checking was a feature intended to increases performance. It would be a shame to need it elsewhere. Would it be possible to reintroduce "allowing foreign types" as an option? const {create, env} = require('sanctuary');
const {map} = create({
env: env.concat(myTypes), //I have some custom types
checkTypes: process.env.NODE_ENV === 'development', //My user-base likes this ;)
allowForeign: true //Since I'm making a lib, I should expect types outside of my env
}); This would allow library authors to build on top of Sanctuary, providing its fantastic type-checking for known types, without having to burden users with the creation of an environment or the concept of unknown types. AMENDMENT: I just realized I'm looking at it from my own perspective as a library author. The question from Sanctuary's perspective would be: "Would Sanctuary
It would, in my proposal.
Me too. And I think the ideas presented in sanctuary-js/sanctuary-def#74 are much more elegant. However, I think the complexity of wiring up the Sanctuary env is quite daunting and it keeps bothering me that library authors have to pass along the env if they wish to make meaningful use of Sanctuary. Though using mutation might give us more problems than it solves. :\ |
Actually, this might be a bad idea. It's going to enforce developers to "cut off access" to extending the internal |
So to conclude:
|
Oh, I see. :)
I do like the idea of reinstating const S = require('sanctuary').unchecked; const S = require('sanctuary').create({checkTypes: false, env: []}); Were we to do so, the I'm keen to reinstate |
Using sanctuary-type-classes is absolutely the right approach. ADT libraries are foundational so should not depend on high-level libraries such as Sanctuary. Sanctuary is large and has many dependencies.
|
In resolving conflicts between #216 and #232 I discovered a problem. Consider this example:
Seems fine, doesn't it? Yes, but for the fact that by using
S.map
we're limiting the types with which this method is compatible to the types known toS
.This is very much related to sanctuary-js/sanctuary-def#74.
As things stand, I see two workarounds:
S.create({checkTypes: false, env: []}).map
in place ofS.map
; orcreate :: { checkTypes :: Boolean, env :: Array Type } -> Module
function which returns anIdentity
constructor compatible with the desired set of types.The text was updated successfully, but these errors were encountered: