[Haskell-cafe] Closed classes

David Feuer david.feuer at gmail.com
Wed Feb 17 22:21:25 UTC 2016

I was thinking about ~two notions of "closed class" yesterday, and I'm
curious if anyone's done any work on either concept. In each case, the
class definition is followed by *all* of its instances, and the instances
are checked *in order* (rather than based on specificity and

No backtracking:

If the instance head matches, GHC commits to it. Associated types are
treated as closed type families, and would work just the same (I don't
think any significant extension to the closed type family mechanism would
be required). This seems to make a very nice parallel to the usual open
classes with open associated types. And it lets you combine overlapping
instances with associated types without (I believe) risking type safety.


GHC does not commit to the instance until it has satisfied the instance
constraints. This lets instance writers offer multiple alternative instance
constraints. Associated types would be a good bit trickier. One option
would be to require all instances with the same head to share a type/data
instance. The other (much more invasive) option would be to allow the
instance chosen to guide the type selection, which would push the
backtracking into the type checker.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160217/63cc1c4d/attachment.html>

More information about the Haskell-Cafe mailing list