Skip to content

Improve consistency with other libraries #184

Open
@milesfrain

Description

@milesfrain

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 for Array and Void
  • Void defines the instance for Show
  • Show defines the instance for Array

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 for Show and Semigroup
  • Array defines instances for Show and Semigroup

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs more infoThis issue needs more info before any action can be done.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions