conal / total-map

Finitely represented /total/ maps
Other
15 stars 6 forks source link

Something to think about #1

Closed jfischoff closed 12 years ago

jfischoff commented 12 years ago

The Monoid instance of total-map breaks from the spirit of the Monoid instance in Data.Map. Might make more sense to have Semigroup instance instead similar to the one in this pull request.

conal commented 12 years ago

Hi Jonathan,

Thanks for the suggestion.

The design of total-map is guided by the type class morphism (TCM) principle, and so the class instances emulate those of the semantic model, namely functions. Thus the Monoid instance intentionally agrees with that of function and disagrees with that of Map. You can customize TMap by composing it, e.g., with Maybe, First, or Last. Choosing First gets you the left-biased Map functionality, Last gets the right-biased version (also useful), and other choices give other useful variations.

More discussion in section 4 of Denotational design with type class morphisms.

If my motivation or methodology is still unclear, please let me know.

jfischoff commented 12 years ago

Very cool, I start digesting the material as soon as I can.

Best, Jonathan

On Thu, Jul 5, 2012 at 9:29 AM, Conal Elliott reply@reply.github.com wrote:

Hi Jonathan,

Thanks for the suggestion.

The design of total-map is guided by the type class morphism (TCM) principle, and so the class instances emulate those of the semantic model, namely functions. Thus the Monoid instance intentionally agrees with that of function and disagrees with that of Map. You can customize TMap by composing it, e.g., with Maybe, First, or Last. Choosing First gets you the left-biased Map functionality, Last gets the right-biased version (also useful), and other choices give other useful variations.

More discussion in section 4 of Denotational design with type class morphisms.

If my motivation or methodology is still unclear, please let me know.


Reply to this email directly or view it on GitHub: https://github.com/conal/total-map/pull/1#issuecomment-6783551

conal commented 12 years ago

I just looked more carefully at your Semigroup instance and noticed that you use only one of the defaults. I don't think you could define a correct Semigroup instance without using both defaults. Which raises the question of what "correct" means here. TCM gives an answer I particularly like. As a pleasant side-effect of TCM, the class laws are guaranteed to hold. (All explained in that paper.)