jcpetruzza / barbies

BSD 3-Clause "New" or "Revised" License
92 stars 15 forks source link

Add `DistributiveB` typeclass #27

Closed gergoerdi closed 4 years ago

gergoerdi commented 4 years ago

As discussed in #26.

Note that I am deeply in this territory here, so some generic GShape instances still need to be written: image

gergoerdi commented 4 years ago

I have now added documentation as well. I am eagerly awaiting your response, since there is a project where I'd like to start using this feature.

gergoerdi commented 4 years ago

OK I have resolved most of your feedback. The only remaining items are:

jcpetruzza commented 4 years ago

For DistributiveT, I hope it should be mostly a matter of copying the Barbies.Internal.DistributiveB module, add the extra type parameter to type signatures and use GDistributive 1 instead GDistributive 0 in instances (this is the position where the functor argument occurs in the type)

gergoerdi commented 4 years ago

I think I'm all done.

gergoerdi commented 4 years ago

I have to say though, most of the generic instances are peak "I have no idea what I'm doing" territory. If GHC didn't have typed holes, I would have never been able to write them :)

jcpetruzza commented 4 years ago

@gergoerdi I'm adding some minor clean-ups and documentation updates. I'm presenting the class laws in terms of brecompose / bdecompose and removed bshape since I felt it was only useful for the sake of presenting the laws. If it's something you'd use, I'm happy to add it back. Similarly, I ended up replacing bcollect (which was my suggestion) by bcotraverse that we have the dual of btraverse; bcollect didn't seem too useful with that signature. Let me know what you think!

gergoerdi commented 4 years ago

Great, thanks a lot!

bshape is fully redundant now, because it is trivially recoverable as bdecompose id, so I agree there's no need to keep it.

gergoerdi commented 4 years ago

All tests pass, and hopefully they test the actual relevant laws :)

jcpetruzza commented 4 years ago

@gergoerdi thanks for all your work on this!

gergoerdi commented 4 years ago

Thanks, this is great!