3

I'm working on a fairly simple text-editor for Haskell, and I'd like to be able to highlight static errors in code when the user hits "check."

Is there a way to use the GHC-API to do a "dry-run" of compiling a haskell file without actually compiling it? I'd like to be able to take a string and do all the checks of normal compilation, but without the output. The GHC-API would be ideal because then I wouldn't have to parse command-line output from GHC to highlight errors and such.

In addition, is it possible to do this check on a string, instead of on a file? (If not, I can just write it to a temp file, which isn't terribly efficient, but would work).

If this is possible, could you provide or point me to an example how how to do this?

This question ask the same thing, but it is from three years ago, at which time the answer was "GHC-API is new and there isn't good documentation yet." So my hope is that the status has changed.

EDIT: the "dry-run" restriction is because I'm doing this in a web-based setting where compilation happens server side, so I'd like to avoid unnecessary disk reads/write every time the user hits "check". The executable would just get thrown away anyways, until they had a version ready to run.

Community
  • 1
  • 1
jmite
  • 8,171
  • 6
  • 40
  • 81
  • 1
    I would consider it a added *feature* to get both errors annotated *and* get a working executable from my IDE, but that is just me :) – jamshidh Dec 17 '13 at 02:00
  • It's a little more complicated than that. I'm doing a browser-based thing where they write their code in an editor and it gets stored in a database. I can't divulge too much yet, but it's less of an IDE, but the project involves users submitting code which is run server-side. (SafeHaskell makes this nice and safe.) So, I guess it would be enough to compile it and just throw away the executable, but it seems like extra overhead, especially on a server-side app which could be running multiple compilations at once. – jmite Dec 17 '13 at 02:04
  • 1
    Take a look at ghc-mod. It's designed for just this – daniel gratzer Dec 17 '13 at 02:40
  • Add this as an answer and I'll accept it. Just what I was looking for! – jmite Dec 17 '13 at 03:11

1 Answers1

4

Just to move this to an answer, this already exists as ghc-mod, here's the homepage. This already has frontends for Emacs, Sublime, and Vim so if you need examples of how to use it, there are plenty. In essence ghc-mod is just what you want, a wrapper around the GHC API designed for editors.

daniel gratzer
  • 52,833
  • 11
  • 94
  • 134