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

ch12: The result of comp1 is not proper #638

Open
dzylikecode opened this issue Nov 3, 2022 · 0 comments
Open

ch12: The result of comp1 is not proper #638

dzylikecode opened this issue Nov 3, 2022 · 0 comments

Comments

@dzylikecode
Copy link

original content

const comp1 = compose(sequence(Compose.of), map(Compose.of));
const comp2 = (Fof, Gof) => compose(Compose.of, map(sequence(Gof)), sequence(Fof));


// Test it out with some types we have lying around
comp1(Identity(Right([true])));
// Compose(Right([Identity(true)]))

comp2(Either.of, Array)(Identity(Right([true])));
// Compose(Right([Identity(true)]))

issue

I disagree with the result of comp1(Identity(Right([true]))) will be Compose(Right([Identity(true)])). As it's mentioned in the Identity law:

const identity1 = compose(sequence(Identity.of), map(Identity.of));
const identity2 = Identity.of;

// test it out with Right
identity1(Either.of('stuff'));
// Identity(Right('stuff'))

identity2(Either.of('stuff'));
// Identity(Right('stuff'))

identity1 is equivalent to identity2. And I think comp1 is isomorphic to identity1, which means comp1 is equivalent to Compose.of. So the result of comp1(Identity(Right([true]))) should be Compose(Identity(Right([true]))).

maybe a solution

I'm not sure whether sequence will exchange the containers that are not adjacent, like this:

sequence(A.of, C(B(A(x))));
// A(B(C(x)))

If the law is right, I think the proper comp1 should equal compose(sequence(Compose.of), map(map(map(Compose.of))))

@dzylikecode dzylikecode changed the title ch12: type signature is not proper ch12: The result of comp1 is not proper Nov 3, 2022
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