[Haskell-cafe] Existential type variables in constraints
Richard Eisenberg
rae at richarde.dev
Sat Apr 3 02:54:05 UTC 2021
> On Apr 2, 2021, at 8:54 AM, CASANOVA Juan <Juan.Casanova at ed.ac.uk> wrote:
>
> I honestly cannot see how it could be hard for the compiler to realize that
>
> instance (Ord a, forall b. Ord b) => Class1 a where
> fun1 = (<)
>
> and
>
> instance (forall b. (Ord a, Ord b)) => Class1 a where
> fun1 = (<)
>
> are equivalent. But it doesn't.
Just on this one small point: GHC understands a forall-type as a function, so that (in your second example above) we can produce Ord a and Ord b only once a b has been chosen. Because nothing forces the choice of b, GHC cannot proceed and extract the Ord a constraint.
More generally, I don't think there is a good answer for what you want to do, short of using type families instead of functional dependencies. With type families, you can name the new type in terms of the type variables you have in scope.
I hope this is helpful!
Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210403/7c171903/attachment-0001.html>
More information about the Haskell-Cafe
mailing list