
#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 AntC): Replying to [ticket:16070 simonpj]:
... quite a bit shorter.
To be clear what's intended here: the "shorter" could be achieved by something akin to Common Subexpression Elimination. That is: * Common type (sub-)expressions appearing in constaints. * Replace by a bare unification tyvar. * Add a `~` constraint between the tyvar and the type expression. But wait, there's more:
After all, it does some similar abbreviation with type classes. Where we could infer `(Ord a, Eq a)` we collapse out the `Eq a` and just infer the context `(Ord a)`.
The `~` constraint generated for the common type expression `FieldType` is exactly the superclass constraint for `HasField`, just as `Eq a` is a superclass constraint for `(Ord a)`. Note also a later comment on that github discussion that the `FieldType` constraint holding implies there's a `HasField` instance -- because `FieldType` is an Associated Type. Using that implication seems harder: Assoc Types are trreated as sugar for top-level type families/not necessarily grounded in instances, which already gives trouble.
There is nothing record-specific about this ticket. It's just about
using inferred equality constraints to simplify the inferred signature. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/16070#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler