Closed Type Families: separate instance groups?

Simon Peyton Jones simonpj at microsoft.com
Thu Jun 4 09:22:38 UTC 2015


I think it's pretty good as-is.

* Use an open family (with non-overlapping instances) to get yourself
  into part of the match space:
     type instance OpenF (Foo b c) = FFoo (Foo b c)

* Use a closed family (with overlap and top-to-bottom matching) to
  deal with that part of the space:
      type family FFoo a where
         FFoo (Foo Int c) = ...

Doing this was a HUGE improvement, allowing us to cleanly split the
issues of top-to-bottom matching from those of non-overlapping open
families. 

|  It also BTW cuts us off from using Closed Families as Associated types
|  separated into their Class instances.

I don't understand this comment. Can you give an example that the current setup does not handle?

Simon


|  -----Original Message-----
|  From: Glasgow-haskell-users [mailto:glasgow-haskell-users-
|  bounces at haskell.org] On Behalf Of AntC
|  Sent: 04 June 2015 01:54
|  To: glasgow-haskell-users at haskell.org
|  Subject: Re: Closed Type Families: separate instance groups?
|  
|  > Richard Eisenberg <eir <at> cis.upenn.edu> writes:
|  >
|  > You can always define a helper closed type family and have an open
|  > type family instance just call a closed type family.
|  
|  Thank you Richard, you mean like:
|  
|      type family OpenF a
|  
|      ...
|  
|      type instance OpenF (Foo b c) = FFoo (Foo b c)
|      type family FFoo a where
|        FFoo (Foo Int c) = ...
|        ...
|  
|  OK. (Seems rather verbose.)
|  
|  >
|  > Having closed type families, as opposed to branched instances, just
|  > seemed like a cleaner way to package the new functionality.
|  > There really wasn't much to it other than aesthetics, if I recall
|  the
|  > conversations correctly.
|  
|  I recall the conversation quite well.
|  (In fact I think it was me who suggested type family ... where ... ) I
|  think it was less to do with aesthetics, and more to do with reducing
|  verbosity in a common use case.
|  
|  It somehow doesn't seem as clean as old-fashioned overlapping
|  instances.
|  (I agree it does seem cleaner than overlaps with FunDeps.)
|  
|  It also BTW cuts us off from using Closed Families as Associated types
|  separated into their Class instances.
|  I think there's two use cases going on:
|  - one where we want to see all the instances together
|     that fits well to type family ... where ...
|  - t'other where we want everything to do with a type constructor
|  together
|     that fits better with the separate instances
|  
|  AntC
|  
|  
|  
|  _______________________________________________
|  Glasgow-haskell-users mailing list
|  Glasgow-haskell-users at haskell.org
|  http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users


More information about the Glasgow-haskell-users mailing list