ADTs defined using S functions are compatible only with types known to S
See original GitHub issueIn resolving conflicts between #216 and #232 I discovered a problem. Consider this example:
//# Identity#fantasy-land/traverse :: Applicative f => Identity a ~> (a -> f b, c -> f c) -> f (Identity b)
Identity.prototype['fantasy-land/traverse'] = function(f, of) {
return S.map(Identity, f(this.value));
};
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 to S
.
This is very much related to sanctuary-js/sanctuary-def#74.
As things stand, I see two workarounds:
- use
S.create({checkTypes: false, env: []}).map
in place ofS.map
; or - provide a
create :: { checkTypes :: Boolean, env :: Array Type } -> Module
function which returns anIdentity
constructor compatible with the desired set of types.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Reading 12: Defining ADTs with Interfaces, Generics ...
Today's class is about various ways to implement abstract data types, including: interfaces: separating the interface of an ADT from its implementation; ...
Read more >AbstractDataTypes
Abstract data types are data types whose implementation is not visible to their user; from the outside, all the user knows about an...
Read more >[Solved] Using ADTs abstract data types has advantages ...
ADT's or abstract data types facilitate developers to use various functions just by importing the required library and using associated functions without ...
Read more >Abstract Data Types
Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of values and a set...
Read more >Abstract Data Types in C
With procedural abstraction, we use functions based on their signature and documentation without having to know details about their definition.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
Oh, I see. 😃
I do like the idea of reinstating
S.unchecked
—I prefer “unchecked” to “unsafe”—for ergonomics:Were we to do so, the
checkTypes
member of the{ checkTypes :: Boolean, env :: Array Type }
record would become redundant, as you noted.S.create
would only be necessary for creating type-checked modules with custom environments, so we could change its type toArray Type -> Module
. There are two minor drawbacks of this approach:S.create
would no longer mirror$.create
, and switching based onprocess.env.NODE_ENV
or similar would be slightly messier.I’m keen to reinstate
S.unchecked
if you think it’s a good idea. We may or may not decide to changeS.create
while we’re at it.