[GHC] #11534: Allow class associated types to reference functional dependencies
GHC
ghc-devs at haskell.org
Wed Mar 2 09:21:58 UTC 2016
#11534: Allow class associated types to reference functional dependencies
-------------------------------------+-------------------------------------
Reporter: ekmett | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler (Type | Version: 7.10.3
checker) | Keywords: TypeFamilies,
Resolution: | FunctionalDependencies
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: Other | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
Yes I've often thought of doing this. An alternative, which no one has
ever fleshed out, would be to extend System FC somehow to provide evidence
for functional dependencies. But what Adam suggests here is more or less
precisely that; the `Foo` class is a record that has `(j ~ Foo_FD1 i)` as
one of its fields; that is, evidence that `(j ~ Foo_FD1 i)`.
I worry a bit about how elaborate the translation might be, and whether
error messages might mention these strange functions.
An alternative is just to use the type-family approach in the first place.
Hmm. Maybe we could use default declarations to make it even easier:
{{{
class j ~ Foo_FD1 i => Foo i j where
type Foo_FD1 i :: *
type Foo_FD1 i = j
instance Foo Int Bool where
-- Nothing
}}}
This is currently rejected because `j` is not bound on the LHS of the
default decl, but if we allowed it, then we'd get, well, precisely what we
want.
Oh, the idea doesn't work at all. Consider
{{{
instance Foo a b => Foo [a] [b] where
type Foo_FD1 [a] = [F a] -- This RHS is not so easy to generate!
}}}
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11534#comment:25>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list