[Haskell-cafe] Domain specific error messages

Corentin Dupont corentin.dupont at gmail.com
Fri Feb 6 11:21:56 UTC 2015


I think it would be a great improvement.
However I'm wondering about the initial goal, that was making DSLs: the
creator of a DSL is an Haskell expert (more or less), but not a GHC expert.
So I'm wondering if the knowledge of TcError and all should be required...

How would that work in general? I suppose the creator of a library would:
- provide a nice DSL to interface with,
- also provide instructions to the compiler for how to handle errors.
Should this be done through a language pragma?
Then the user of the DSL would simply create his program, compile and get
the nice error messages.
How to be sure that the modified error messages remain local to the DSL or
to the library, and does not pollute all the rest of the compilation?


On Fri, Feb 6, 2015 at 11:17 AM, Simon Peyton Jones <simonpj at microsoft.com>
wrote:

>   I think this is very similar to what Idris supports for reflecting on
> errors:
> http://www.itu.dk/people/drc/drafts/error-reflection-submission.pdf
>
>
>
> Aha!  Yes, thank you for jogging my memory.  I had a good conversation
> with David Christiansen about this at ICFP, about this very topic, and
> whether we could steal Idris’s clever ideas and put them in GHC.
>
>
>
> ·         He subsequently wrote a blog post
> <http://www.davidchristiansen.dk/2014/09/06/pretty-printing-idris/>
>
> ·         Incidentally, in case it’s not clear this thread on Haskell
> Café
> <https://www.haskell.org/pipermail/haskell-cafe/2014-November/117054.html>
> goes back to Nov 14.  The first message in the series had more useful links
>
>
>
> David’s idea is would have much broader scope than just TcErrors.  Much of
> the infrastructure is in place already, since error message are SDocs (an
> abstract type, private to GHC), not strings.
>
>
>
> Design work needed. Start a wiki page.  Articulate a vision.  Discuss
> alternatives.
>
>
>
> Simon
>
>
>
> *From:* Haskell-Cafe [mailto:haskell-cafe-bounces at haskell.org] *On Behalf
> Of *Alejandro Serrano Mena
> *Sent:* 06 February 2015 08:24
> *To:* Adam Gundry
> *Cc:* Haskell Cafe
> *Subject:* Re: [Haskell-cafe] Domain specific error messages
>
>
>
> I think this is very similar to what Idris supports for reflecting on
> errors:
> http://www.itu.dk/people/drc/drafts/error-reflection-submission.pdf
>
>
>
> 2015-02-06 8:53 GMT+01:00 Adam Gundry <adam at well-typed.com>:
>
>  [Re-sending to haskell-cafe since I used the wrong From address...]
>
> This is something that has been on my mind for a while, particularly
> following discussions at the last ICFP and prompted by the work on
> typechecker plugins in GHC [1]. I think I see a way to proceed, though I
> don't know whether I will have time to implement it for a while. I'd be
> interested to hear about other approaches.
>
> Suppose we define an ADT representation of all the typechecker error
> messages, e.g. something roughly like
>
>     data TcError = CustomError String
>                  | CouldNotUnify Type Type
>                  | NoClassInstance ...
>
> In GHC all the relevant messages are generated in the
> typechecker/TcErrors module, so this shouldn't be too hard to arrange.
> Now we can extend plugins with the ability to supply a function
>
>     tcPluginAdjustErrors :: [TcError] -> TcPluginM [TcError]
>
> and run the plugged-in function between generating and reporting the
> errors. Thus a library defining a DSL could also provide a plugin to
> supply more informative error messages.
>
> This is a fairly quick-and-dirty approach, because the plugin would be
> quite tightly coupled to GHC, even though it could be written and
> distributed separately. But it might be one way of making progress. (It
> also occurs to me that such an ADT might allow GHC to define a
> machine-readable serialisable format for its error messages, to allow
> post-processing by external programs.)
>
> Adam
>
> [1] https://ghc.haskell.org/trac/ghc/wiki/Plugins/TypeChecker
>
>
> On 05/02/15 09:54, Corentin Dupont wrote:
> > Hi all,
> > I have been very interested by this discussion when Alberto started it.
> > As there been any progress?
> > The problem is very acute in the Nomyx game I'm developing
> > (www.nomyx.com <http://www.nomyx.com>).
> > The game is based on a DSL, it's working well, but at the moment only
> > expert Haskell developers can play...
> > I think cryptic error messages is part of the problem.
> > How to improve that?
> > For example, a common error message is the following:
> >
> > Won't Compile
> > <interactive>:5:28:
> >     Couldn't match type ‘'NoEffect’ with ‘'Effect’
> >     Expected type: Exp Effect ()
> >       Actual type: Exp NoEffect ()
> >     In the expression: e_1
> >     In the expression: (let e_1 = do { ... } in e_1) :: Exp Effect ()
> >
> > It's not so helpful and exposing Nomyx internals.
> > A better error message would be to hint that the player forgot a
> "liftEffect" instruction.
> >
> > The only quick-and-dirty solution I see is to pattern-match for it and
> display an additional hint line...
>
>
>
> --
> Adam Gundry, Haskell Consultant
> Well-Typed LLP, http://www.well-typed.com/
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150206/3d6838ba/attachment.html>


More information about the Haskell-Cafe mailing list