Description
There's a lot in common among containers such as List
, Array
, Set
, but their APIs drift out of sync. What's a good strategy to keep everything up to date?
We could continue to apply techniques such as #183 across these libraries, but that requires constant manual intervention.
Would it be appropriate to use more type classes to enforce common interfaces? Or should we avoid those, as suggested in https://harry.garrood.me/blog/down-with-show-part-1/ ? I still don't have a good understanding of how using more typeclasses leads to trouble.
For example we could have a SetLike
type class that provides intersection
, union
, difference
, etc. that List
, Array
, Set
would all have an instance of. A similar strategy could have also helped us avoid #178 and needing to remember to address purescript/purescript-arrays#192. Interfaces could also cut down on the burden of maintaining duplicated documentation for all of these duplicated functions.
Another minor bit of messiness is that we currently have both intersect
and intersection
, depending on the container. Of course this can be fixed without resorting to typeclasses, but could also have been prevented by embracing more typeclasses.
Also, what determines whether a typeclass instance is defined in the type or the class? It seems somewhat arbitrary. For example:
Semigroup
defines the instances forArray
andVoid
Void
defines the instance forShow
Show
defines the instance forArray
Things would be a bit more organized if the policy in core was to always define instances in the type, which would look like the following:
Void
defines the instance forShow
andSemigroup
Array
defines instances forShow
andSemigroup