-
Notifications
You must be signed in to change notification settings - Fork 246
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
Add foldMap and fold #1281
Add foldMap and fold #1281
Conversation
Hmm I'm not sure these functions really belong here for a couple of reasons. For starters we don't want to drag in the entire algebra hierarchy into I think there is potential for wrapping |
|
I accept the argument that it shouldn't be in |
|
Thinking out loud... and bearing in mind that lists-modulo-permutation with [] and ++ is one concrete representation of the free commutative monoid, and one close to the heart of anyone who tried verification of sorting algorithms... a long time ago... Why not add a new layer to the Algebra.* module hierarchy that specifically introduces Free structures. That way, such a module imports from the underlying algebra, and the underlying concrete representing type, but produces an abstract construction satisfying the suitable universal property... |
Could you give an example of what a definition of such a free structure would like? |
Hmmm... I see that might require a bit more than mere casual effort, as well as making me think harder about how to understand the existing Algebra.* hierarchy. But it definitely strikes me that
|
As it turns out, the proper notion of I've been meaning to revisit free commutative monoid. I've got a completely bit-rotted version that goes all out and proves it's indeed the expected left adjoint. The tricky part is that everything needs to go "Setoid" (which is fine wrt the current library) and proof-relevant. (Actually, I've got multiple bit-rotted versions of that in that repo, I'm not even sure which one is the least rotted.) There are quite a few 'Free' structures in that repo that are not bit-rotted. I really need to finish writing that paper... The interesting thing is that there's a couple more properties that are nice that arise when you prove full adjoint instead of just 'free'. |
I'm revisiting is. Was there any problem with putting the properties in |
So... none of the above suggestions had Instead, I'd still argue for a place under Indeed, for a general (haskell) |
I agree with @jamesmckinna . |
As I've said before, I really don't think that things like If I understand what @jamesmckinna is proposing, it's to have in This will work find until we have two different representations of lists, at which point it's not clear where they should live. (this is not an idle concern, I've been off-and-on-again working on Okaski random-access lists). It also falls if we also want to have If we instead have a generic specification of what a |
Nathan, thanks once more for the considered response. While I am indeed arguing for something like Then As for the precedent(s) of optimising for the common cases of Or have I misunderstood what you want under |
What would the contents of such a module be? |
We would, of course, also need the definitions of |
Before this morning it had been a long time since I've thought about this PR, so I'll state my current design idea explicitly: Somewhere in the In
I'd also like to add similar for I don't understand why you think we need to define an |
Well, looking at |
I really dislike that
|
I think the needs that this aimed to fulfill have now been satisfied. |
List is a free monoid
I'd like to have some properties for bag-and-set equality.
foldMap f
is a commutative monoid morphism from lists with bag equality, and an idempotent commutative monoid morphism from lists with set equality, but I don't know how to prove these.