|
|
|
# Multi Parameter Type Classes Dilemma
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[MultiParamTypeClasses](multi-param-type-classes) are very useful, but mostly in the context of [FunctionalDependencies](functional-dependencies). They are particularly used in the [ monad transformer library](http://www.haskell.org/ghc/docs/latest/html/libraries/index.html) found in fptools. The dilemma is that [ functional dependencies are "very, very tricky"](http://www.haskell.org//pipermail/haskell-prime/2006-February/000289.html) (spj). [AssociatedTypes](associated-types) are promising but unproven. Without a solution, Haskell' will be somewhat obsolete before it gets off the ground.
|
|
|
|
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
|
|
|
|
- [ Understanding functional dependencies via Constraint Handling Rules](http://research.microsoft.com/%7Esimonpj/papers/fd%2Dchr/), Martin Sulzmann, Gregory J. Duck, Simon Peyton Jones, and Peter J. Stuckey. Revised Feb 2006
|
|
|
|
- P. J. Stuckey and M. Sulzmann. [ A theory of overloading](http://www.comp.nus.edu.sg/~sulzmann/chr/download/theory-journal.ps.gz). ACM Transactions on Programming Languages and Systems (TOPLAS), 27(6):1-54, 2005.
|
|
|
|
|
|
|
|
## Options for solving the dilemma
|
|
|
|
|
|
|
|
|
|
|
|
1. Examine a limited version of functional dependencies (see below for one solution)
|
|
|
|
1. Put [AssociatedTypes](associated-types) on the fast-track for sainthood
|
|
|
|
1. Punt: declare [FunctionalDependencies](functional-dependencies) as an extension and figure out a way to "bless" extensions
|
|
|
|
1. Find a subset of [FunctionalDependencies](functional-dependencies) that is guarenteed to be a subset of what is expressible with [AssociatedTypes](associated-types). This would ensure no Haskell' programs become unexpressable if FDs switched to [AssociatedTypes](associated-types) in the future.
|
|
|
|
|
|
|
|
## Options that don't actually solve the dilemma
|
|
|
|
|
|
|
|
|
|
|
|
1. Standardize without [MultiParamTypeClasses](multi-param-type-classes) or [FunctionalDependencies](functional-dependencies)
|
|
|
|
1. Standardize [FunctionalDependencies](functional-dependencies) even though [ they are tricky](http://www.haskell.org//pipermail/haskell-prime/2006-February/000289.html).
|
|
|
|
|
|
|
|
## Tickets
|
|
|
|
|
|
|
|
|
|
|
|
- [solve the MultiParamTypeClassDilemma](https://gitlab.haskell.org//haskell/prime/issues/90)
|
|
|
|
|
|
|
|
## Proposed Solutions
|
|
|
|
|
|
|
|
|
|
|
|
1. Adopt functional dependencies with the FD-conditions from the [ CHR paper](http://research.microsoft.com/Users/simonpj/Papers/fd-chr/) together with the "complex relaxation rule" described at the bottom of the [FunctionalDependencies](functional-dependencies) page (also see the CHR paper, sect. 6).
|
|
|
|
|
|
|
|
|
|
|
|
Pro:
|
|
|
|
|
|
|
|
|
|
|
|
- allows a safe version of [FunctionalDependencies](functional-dependencies) that can support the monad transformer library
|
|
|
|
|
|
|
|
|
|
|
|
Con:
|
|
|
|
|
|
|
|
|
|
|
|
- complex specification for what is and is not allowed in classes and instance with functional dependencies
|
|
|
|
- not clear whether this could be forwards-compatible with associated types |