-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
Consider changing typeclasses signatures to be always data-last #1216
Comments
I did some further testing, it doesn't look so bad performance wise (roughly 30% loss but case dependent), in case of critical places there are still means of optimization by exposing specific data-first functions outside of the instances so I'll also vote for it. |
@raveclassic I have a proposal to make this change kind of "backward compatible". Switching to data-last type class is indubitably a breaking change for "power users" (e.g. library authors). However "normal" users always interact with type class instances only as a way to configure constrained functions, for example import * as A from 'fp-ts/lib/Array'
import * as E from 'fp-ts/lib/Either'
import { pipe } from 'fp-ts/lib/pipeable'
pipe(
[E.right(1), E.right(2), E.right(3)],
A.sequence(E.either), // <= as a user I really don't care what `E.either` actually is
E.bimap(
() => 'error',
() => 'ok'
)
) Now Those internal instances are data first now. Here's come the trick, what if we export a data-last |
How would you do that? |
EDIT: I'm temporary using |
Well... The trick with I'm not sure it's worth the maintenance effort. I'd rather spend a couple of days migrating to a data-last version of the lib. |
Yeah, actually I'm not fond of this solution neither, but since I'm going to split the mega instances, it's kind of a unique occasion and I wanted to hear your feedback and to make sure all paths were explored before proceeding. |
I'm totally ok to split the instances if they will still contain each other const functorEither = {
URI,
map: ...
}
const applyEither = {
...functorEither,
ap: ...
} Even more, I'd suggest to change name to |
@raveclassic do you mean "data type name in the instance"? Another question: if all Note. Please do not answer here, since now the argument is no more strictly related to data-last type classes I opened #1237 |
(super-early-pre-alpha version) branch: https://github.com/gcanti/fp-ts/tree/3.0.0 or |
Pros (from #942 (comment))
pipe
is an idiomatic way to usefp-ts
however its abstract core - the typeclasses - have signatures not suitable for this idiomatic way out of the box and require some messy (redundant IMO) steps like callingpipeable
, destructuring, reexporting and so on. When they actually could be used as is.HKT
dictionary. This doesn't make much sense because the type is already "bundled" in the transformer instance (for example the result ofgetOptionM
already contains info aboutOption
and passedM
.pipeable
module itself is a mess with no sensible profit - it just fixes data-first typeclasses when they could be data-last by design completely eliminating the need for this module.Cons
Prior art
EDIT: I agree with the proposed change, so I'll add my vote as 👍
The text was updated successfully, but these errors were encountered: