[GHC] #16070: Better inferred signatures
GHC
ghc-devs at haskell.org
Mon Dec 24 08:40:00 UTC 2018
#16070: Better inferred signatures
-------------------------------------+-------------------------------------
Reporter: simonpj | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.3
Resolution: | Keywords: TypeFamilies
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by simonpj):
Yes, I was thinking of the following algorithm. The algorithm is used
when inferring the type of a function (and only on that occasion).
Specifically, it is an enhancement to the existing function
`TcType.mkMinimalBySCs`.
Suppose `C` is declared thus, with a type variable on the left of a
superclass equality:
{{{
class (b ~ ty, ...) => C a b c
}}}
`mkMinimalBySCs` is given a list of predicates, `preds`, such as `(Ord a,
Eq a)`, or `(HasField "foo" r (FieldType "foo" r))`.
It's business is to abbreviate it to an equivalent one.
* For each predicate `(C t1 t2 t3)`, where `t2` = `ty[t1/a,t3/c]`, then
replace all occurrences of `t2` in `preds` with `x` where is a fresh
skolem variable.
So if
{{{
preds = [ HasField "bar" r (FieldType "bar" r)
, HasField "foo" r (FieldType "bar" r) ]
}}}
we'll spot the condition on the first predicate, and replace `(FieldType
"bar" r)` with `x` throughout:
{{{
preds = [ HasField "bar" r x
, HasField "foo" r x ]
}}}
Now we need to
* Quantify over `x` as well as whatever else we were quantifying over
before
* Apply that same substitution to the type we are quantifying over (to
catch the case of `g` in the `Description`.
So it's more than just modifyign `mkMinimalBySCs`.
There's something a bit unsatisfying about this: during flattening we have
all these common sub-expressions neatly identified. It seems a pity to un-
flatten them away only to then have to rediscover them.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16070#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list