[GHC] #15470: Record projections with ambiguous types
GHC
ghc-devs at haskell.org
Wed Jan 23 13:53:54 UTC 2019
#15470: Record projections with ambiguous types
-------------------------------------+-------------------------------------
Reporter: sweirich | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: 8.10.1
Component: Compiler | Version: 8.4.3
Resolution: | Keywords:
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 RyanGlScott):
I'm a bit leery about changing the order of type variables just to support
this one use case, especially since if we had the ability to bind type
variables in lambdas, then we could implement these record projections
without the need to change the original types:
{{{#!hs
type family F a
data T a = MkT (forall a. F a)
fld :: T -> (forall a. F a)
fld (MkT x) = (\@a -> x @a)
}}}
Moreover, this type-variable-reordering hack really only works in one
direction. That is to say, you can define record selectors since the
position of the `forall` allows you to float those type variables to the
front, but you can't define a synonym for the constructor itself, like so:
{{{#!hs
mkT :: (forall a. F a) -> T
mkT = ???
}}}
Here, we can't float the `a` to the front, so we're left without a way to
implement this. With type variables in lambdas, we could, however:
{{{#!hs
mkT :: (forall a. F a) -> T
mkT x = T (\@a -> x @a)
}}}
Of course, I'm speculating a bit here and assuming that the ambiguity
check won't kick in on the examples above. (I have no way of knowing this,
since type-variables-in-lambdas aren't yet implemented.) But it seems like
it could be a viable alternative.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15470#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list