Reducing all type family applications as far as possible

ÉRDI Gergő gergo at
Fri Oct 28 09:50:19 UTC 2022


Is there a way to have GHC reduce all (reducable) type familiy 
applications? For example, if I have

type family Id x where
   Id x = x

foo :: Bool -> Id Bool
foo x = x

then I would like the `Id` of `foo` to have type `Bool -> Bool`, and the 
generated Core should be either `foo = \x -> x` or, if that's asking 
for too much, at least something like `foo = \x -> x |> 
(somePossiblyOvercomplicatedCoercion :: Bool ~ Bool)`.

Is there already some functionality for this in GHC? If not, how messy 
would it be to implement it as a separate `CoreProgram` transformation 
just after desugaring? It'd need to be immediately after desugaring 
because I would like e.g. the specialiser to already specialise in terms 
of these reduced types.


More information about the ghc-devs mailing list