[Haskell-cafe] Increasing Haskell modularity

Jon Sterling jon at jonmsterling.com
Wed Oct 1 15:55:12 UTC 2014


Gershom,

As far as Haskell is concerned, yes, I think orphan instances should go.

However, they are very useful! It is our aversion to using them which
prevents us from splitting things into separate, modular libraries: for
instance, library A provides type classes, library B provides unrelated
types, library C provides A instances for B types. When people use the
word "modularity", it is assumed that this is one of the things it can
do, so it's kind of funny to hear the word used in a sense which rules
out this case.

But as you and Ed have argued in the past, orphan instances in Haskell
actually cause a fair amount of problems, which I consider to be a
*ringing* indictment of type classes as the only means of modular
abstraction. If we outlaw the orphans, we'll rule out some bad cases,
and at the very least make crystal clear the actual problem of
modularity such that people will not easily confuse Haskell type classes
with a solution to it, as some do now.

So I'm in favor.

Kind regards,
Jon

On Wed, Oct 1, 2014, at 08:25 AM, Gershom B wrote:
> It seems to me the far easier choice, in ditching the feature “not
> worth the problem” is simply to eliminate orphan instances as in
> “Extension 1” described in Edward Yang’s blog post
> (http://blog.ezyang.com/2014/09/open-type-families-are-not-modular/).
> 
> I’d like to open up a further discussion on this at some future point,
> as I’m convinced that there is no “legitimate” use of orphans in the
> Haskell ecosystem that cannot be substituted for with other safer and
> more straightforward techniques.
> 
> -g
> 
> 
> On October 1, 2014 at 9:26:45 AM, Gesh (gesh at gesh.uni.cx) wrote:
> > Dear Café,
> > Edward Yang recently wrote about the non-modularity of the current semantics
> > for typeclasses[0] and open type families[1].
> > Given these problems, we can either try to work around the problem, or
> > decide
> > whether these features are worth the problems.
> > The specific pair of proposals I am making are the following:
> > * Give up on global uniqueness of typeclass instances.
> > Oleg discusses adding local typclass instances without losing
> > coherence in his
> > reflection paper[2]. If we adopt his proposal, and weaken global
> > uniqueness of
> > instances to local uniqueness, we can then say that typeclass
> > instances in a
> > module are considered more local than imported instances, and therefore
> > override them.
> > Since instances will be locally unique, we don't have to pass around
> > dictionaries. Data types that expect globally unique instances, such
> > as Set,
> > will have to store dictionaries, however.
> > * Give up on non-associated open type families.
> > This I have researched less well, but it seems to me that these have
> > no use
> > case. Since one can make whatever instances one wishes for these type
> > families, one can't do anything useful with values of their instances.
> > In other words, values of type F a are morally of type (forall a. a).
> > Thus, the only way I can see these being useful is if anyone creating an
> > instance of the family must also provide functions that can work with
> > these
> > instances, which brings us back to the case of associated types.
> >
> > As far as I can see, these two features are useless and impeding the
> > drive to
> > make Haskell more modular. Therefore, my questions for you are twofold:
> > * Is there a reason to keep these features?
> > * If not, why don't we drop them?
> >
> > Awaiting your criticism and ire,
> > Gesh
> >
> > [0] -
> > http://blog.ezyang.com/2014/07/type-classes-confluence-coherence-global-uniqueness/
> > [1] - http://blog.ezyang.com/2014/09/open-type-families-are-not-modular/
> > [2] - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.112.7819
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list