instance error verbosity - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Torsten Schmits

is there a verbosity flag that supplies more information about missing instances? it would be nice to have the locations of where the instance was requested, not only the transitive callsite.

Lysxia

Probably not. That sounds like a nice feature request.

Torsten Schmits

coincidentally, I built a similar thing for Scala

Steven Shaw

Do you have an example of the error message that needs improvement? I'm having trouble understanding what you mean by transitive call site.

Torsten Schmits

sure!

class Foo a where

class Bar a where

instance Foo a => Bar a where

f :: Bar a => a
f = undefined

g :: Int
g = f

This results in the error

    * No instance for (Foo Int) arising from a use of `f'
    * In the expression: f
      In an equation for `g': g = f

where I would call Foo a transitive dependency of f via Bar, with the callsite being the equation for g.
In this case, I would like ghc to tell me that Foo was explicitly depended upon in the Bar instance.

Steven Shaw

Thanks, I've never noticed that before. It's a pretty terrible error message since you have no idea where (Foo Int) is needed.

Steven Shaw

I noticed that I had to put the following at the top the file when I tried your example code:

{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE MonoLocalBinds #-}

I wonder if those extensions have a bearning on the poor error message?

Steven Shaw

It doesn't look like removing those extensions helps. I was able to remove the extensions by tweaking the example to :

module Foo where

class Foo q where

class Bar a where

instance Foo a => Bar [a] where

f :: Bar a => a
f = undefined

g :: [Int]
g = f

The error message remains the same.

Steven Shaw

Out of curiosity, I tried Idris 2, hopeful that the situation there is better.

module Foo

interface Foo q where

interface Bar a where

Foo a => Bar (List a) where

f : Bar a => a
f = f

g : List Int
g = f

The error is

Foo.idr:13:5--13:6:While processing right hand side of g at Foo.idr:13:1--14:1:
Can't find an implementation for Bar (List Int) at:
13      g = f
            ^

This is correct and perhaps better than the GHC error message. However, It would be nice to know that an implementation of Foo Int would solve the problem.

Torsten Schmits

yeah, it's weird that this is not a first class concern. same thing bothered me five years ago in scala so much that I made this plugin

better implicit errors for scala. Contribute to tek/splain development by creating an account on GitHub.
Steven Shaw

That's cool. Nice that you could address it using a compiler plugin.