
Hmm, no I don't think that Flattening is a very serious problem:
Firstly, we can somehow get around that if we use implication constraints and higher-order flattening
variables. We have discussed that (but not implemented). For example.
forall a. F [a] ~ G Int
becomes:
forall a. fsk a ~ G Int
forall a. true => fsk a ~ F [a]
Secondly: flattening under a Forall is not terribly important, unless you have type families that dispatch on
polymorphic types, which is admittedly a rather rare case. We lose some completeness but that's ok.
For me, a more serious problem are polymorphic RHS, which give rise to exactly the same problems for type
inference as impredicative polymorphism. For instance:
type instance F Int = forall a. a -> [a]
g :: F Int
g = undefined
main = g 3
Should this type check or not? And then all our discussions about impredicativity, explicit type applications etc become
relevant again.
Thanks!
d-
From: Simon Peyton-Jones
Sent: Friday, April 05, 2013 8:24 AM
To: Manuel M T Chakravarty
Cc: Iavor Diatchki; ghc-devs; Dimitrios Vytiniotis
Subject: RE: Restrictions on polytypes with type families
Manuel has an excellent point. See the Note below in TcCanonical! I have no clue how to deal with this
Simon
Note [Flattening under a forall]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Under a forall, we
(a) MUST apply the inert subsitution
(b) MUST NOT flatten type family applications
Hence FMSubstOnly.
For (a) consider c ~ a, a ~ T (forall b. (b, [c])
If we don't apply the c~a substitution to the second constraint
we won't see the occurs-check error.
For (b) consider (a ~ forall b. F a b), we don't want to flatten
to (a ~ forall b.fsk, F a b ~ fsk)
because now the 'b' has escaped its scope. We'd have to flatten to
(a ~ forall b. fsk b, forall b. F a b ~ fsk b)
and we have not begun to think about how to make that work!
From: Manuel M T Chakravarty [mailto:chak@cse.unsw.edu.au]
Sent: 04 April 2013 02:01
To: Simon Peyton-Jones
Cc: Iavor Diatchki; ghc-devs
Subject: Re: Restrictions on polytypes with type families
Simon Peyton-Jones