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

Implement lawful Functor and Traversable instances (if possible) #22

Open
chshersh opened this issue Apr 22, 2019 · 2 comments
Open

Implement lawful Functor and Traversable instances (if possible) #22

chshersh opened this issue Apr 22, 2019 · 2 comments
Labels
Hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted Extra attention is needed interface question Further information is requested

Comments

@chshersh
Copy link
Contributor

No description provided.

@chshersh chshersh added question Further information is requested interface help wanted Extra attention is needed labels Apr 22, 2019
@chshersh chshersh added the Hacktoberfest https://hacktoberfest.digitalocean.com/ label Sep 29, 2019
@0xd34df00d
Copy link

0xd34df00d commented Oct 13, 2019

Looks like it's only possible for those monoids that "make sense" for any contained value type. I can only think of First, Last and maybe some obscure stuff like Data.Functor.Contravariant's Equivalence. Do you think it still makes sense given this?

@chshersh
Copy link
Contributor Author

@0xd34df00d What do you mean by saying monoids that "makes sense"? The idea was to traverse a treap once, mapping all elements and recalculating all monoidal values in nodes. So it's possible to implement a function like this without any problems:

fmap :: Measured n b => (a -> b) -> Treap m a -> Treap n b

However, due to the Functor nature, it's not possible to implement such fmap inside the instance declaration. It maybe possible with -XQuantifiedConstraints, and I've tried to implement this instance, but my knowledge of QuantifiedConstraints is limited. So I would love to hear more expert thoughts on how to do this correctly and whether this can be done or not 🙂

https://github.com/chshersh/treap/blob/d7af2076c7ba3d31fb6b7694bdc0449144e104f9/src/Treap/Pure.hs#L100-L109

And if it cannot be done, let's implement at least fmat with the type signature above and sane name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest https://hacktoberfest.digitalocean.com/ help wanted Extra attention is needed interface question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants