Adding a way to reduce type families in type errors

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a way to reduce type families in type errors

Jakob Brünker
Hi all,

While there is a way to expand type synonyms in type errors (-fprint-expanded-synonyms), as far as I know, the same doesn't exist for type families. For example, the following

type family Foo a where Foo Int = String
type family Bar a :: Maybe (Foo Int) where Bar a = '()

results in the error

Expected kind `Maybe (Foo Int)', but '() has kind `()'

where I'd like to see "Expected kind `Maybe String'".

I'd be interested in trying my hand at implementing a way to see this, either by adding it to -fprint-expanded-synonyms, or as a new flag.

Three questions:
 - Is there already a way to do this that I'm missing?
 - Are there reasons for why this would be a bad idea?
 - Would a proposal be necessary for this?

Thanks,
Jakob

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Adding a way to reduce type families in type errors

Richard Eisenberg-5


> On Nov 21, 2020, at 10:38 PM, Jakob Brünker <[hidden email]> wrote:
>
> Three questions:
>  - Is there already a way to do this that I'm missing?

Not that I'm aware of. GHC sometimes expands type families and sometimes doesn't. The general philosophy has been that expanding type families is usually good and expanding type synonyms is usually bad. But it wouldn't surprise me in the slightest if GHC is inconsistent about this.

>  - Are there reasons for why this would be a bad idea?

If we did it unconditionally, I imagine some error messages would get worse. Adding a new flag would make the interface to GHC more complex, but perhaps it's worth it.

>  - Would a proposal be necessary for this?

For me, it would depend on the invasiveness of the change; however, making type families expand is already what we try to do, so probably not.

But before blazing ahead, you may want to know that my !4149 already prints what you want. Testing your example yields

Scratch.hs:32:52: error:
    • Couldn't match kind ‘()’ with ‘Maybe String’
      Expected kind ‘Maybe (Foo Int)’, but ‘'()’ has kind ‘()’
    • In the type ‘'()’
      In the type family declaration for ‘Bar’

which I imagine is acceptable.

Richard



>
> Thanks,
> Jakob
> _______________________________________________
> ghc-devs mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Adding a way to reduce type families in type errors

Jakob Brünker
Ah, the result produced by !4149 does indeed look good. Thanks!

Jakob

On Mon, Nov 23, 2020 at 4:54 AM Richard Eisenberg <[hidden email]> wrote:


> On Nov 21, 2020, at 10:38 PM, Jakob Brünker <[hidden email]> wrote:
>
> Three questions:
>  - Is there already a way to do this that I'm missing?

Not that I'm aware of. GHC sometimes expands type families and sometimes doesn't. The general philosophy has been that expanding type families is usually good and expanding type synonyms is usually bad. But it wouldn't surprise me in the slightest if GHC is inconsistent about this.

>  - Are there reasons for why this would be a bad idea?

If we did it unconditionally, I imagine some error messages would get worse. Adding a new flag would make the interface to GHC more complex, but perhaps it's worth it.

>  - Would a proposal be necessary for this?

For me, it would depend on the invasiveness of the change; however, making type families expand is already what we try to do, so probably not.

But before blazing ahead, you may want to know that my !4149 already prints what you want. Testing your example yields

Scratch.hs:32:52: error:
    • Couldn't match kind ‘()’ with ‘Maybe String’
      Expected kind ‘Maybe (Foo Int)’, but ‘'()’ has kind ‘()’
    • In the type ‘'()’
      In the type family declaration for ‘Bar’

which I imagine is acceptable.

Richard



>
> Thanks,
> Jakob
> _______________________________________________
> ghc-devs mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs