Question

I have one Fay file which is the heart of my program, however I need some helpers for my logic, for instance a method to replace substrings. From what I understand, if I need such methods which are offered by many Haskell libraries from Hackage directly, I can't use those Haskell libraries, but I must copy-paste the code in my project. So it's what I did, I copy-pasted a "replace" function together with other helpers from the MissingH library in a new file in my project: Utils.hs.

That Utils.hs compiles without problems with Fay. Also I import it in my main Fay file and I get a JS file for the main project file without problems. However at runtime I get the following error:

ReferenceError: Utils$$36$ is not defined

I don't think that Fay will include the code from the helper file in my main JS file, so I'm including both JS files in the loading HTML. And to make even more sure that when I load the main file, that the utils file is loaded, I load it like that:

$.getScript("Utils.js", function(){
    $.getScript("FayConfig.js");
});

But despite this I still get the error. I tried compiling the Utils.hs with "--library" but it didn't help.

So my question is, which setup do I need to achieve that the generated JS will find the helper functions that I put in another HS file, knowing that at compile-time, Fay (apparently) finds them without problems? Is there an example of such a setup online? Most of the Fay uses that I found have all the code in a single HS file, though they often use external Fay code from cabal, as with fay-jquery. In my case, setting up a cabal project just for these simple helpers would be overkill.

Was it helpful?

Solution

Which version of Fay are you using (fay --version)? It seems like you are using a version older than 0.16 where forgetting import Prelude wouldn't give any warnings, see this closed ticket. So upgrade fay and/or add import Prelude.

We're also considering renaming operators in the produced output to make error messages like these easier to understand.

You do not need to invoke fay several times, fay outputs all dependencies into the same js file. So there's no difference from using a cabal package in that regard.

Hope this helps, otherwise please give me a way to reproduce this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top