What do you do when you are dealing with what seems like a bizarre compiler bug, with the compiler being nothing less than GHC? First, pinch yourself — check; then try again, 3 times to be sure — check; clear out 'dist/' and any temporary build files — check; sleep on it — check.
And it's still happening.
I'm trying to use HStringTemplate for my personal blog
software, in particular the
renderf function. I was getting tricky
compilation errors, and in the course of messing around I found the following:
GHC cannot compile a certain function, call it
func1 for now, which uses
renderf. But it compiles and works just fine if another function
(which doesn't use
renderf, but does use a related HStringTemplate function
render) is present in the module, even though
func2 is not used
anywhere in the project. Changing some of the details of what
causes compilation to fail again, though other details can be changed.
That has to be impossible, right? Am I losing my mind?
Ideally I'd create a nice simple test case, but that might take hours, and
changing small things about the voodoo function
func2 seems to destroy its
magical properties, and I'm suspecting the problem is in me. So I'll just post
all my code. The bad news is there are lots of dependencies. The good news is
I have used cabal, so the following instructions should suffice if you have
Download and install 'ella' (CGI web framework I'm writing) and dependencies:
Download and build the blog software:
The build should succeed. Now, the voodoo function is at the end of
src/Blog/Views.hs. Comment it out:
Result - this compilation error.
I don't know whether that compilation error is correct or not, but either way, it seems crazy that it could depend on the existence and implementation of a completely unused function.
For reference, I'm using GHC 6.10.1.
2017 Update - looks like I was bitten by the monomorphism restriction ‘feature’.