0

I'm mixing old JS and new Fay-generated JS, and I'm trying to get a string representation of some data from Fay. I defined

jshow :: Bool -> String
jshow d = show d

It's not just a Bool in the real code, but the type doesn't change the error.

This is compiled with

fay Linguatron.hs --strict Linguatron

And then I call it in JS with

Strict.Linguatron.jshow(trainingData);

when trainingData is the result from another Fay function which I call from JS.

This gives an error that xs is undefined, and this is inside the Fay standard code! It's on line 436, which looks like

// Make a list.
function Fay$$list(xs){
  var out = null;
  for(var i=xs.length-1; i>=0;i--)   //<<-- This line
    out = new Fay$$Cons(xs[i],out);
  return out;
}

The full trace is

Fay$$list               @   linguatron.js:436
Fay$$jsToFay_string     @   linguatron.js:281
(anonymous function)    @   linguatron.js:822
Fay$$$.force            @   linguatron.js:52
Fay$$_                  @   linguatron.js:29
(anonymous function)    @   linguatron.js:173
(anonymous function)    @   main.js:56
m.event.dispatch        @   jquery.js:4670
r.handle                @   jquery.js:4338

I'm using Fey 0.23.1.12 and it happens on Chrome, Safari, and Firefox.

S_FLUID
  • 63
  • 6
  • "when trainingData is the result from another Fay function which I call from JS." - it seems like this would be relevant information here - how exactly are you producing this value? Obviously the argument passed to `Fay$$list` is actually just `undefined` - so what produced that bogus value? – user2407038 May 06 '16 at 22:25
  • It's not undefined, though... the value of `trainingData` at the time of the error is `function ($p2){return new Fay$$$(function(){var x = $p2;var xs = $p1;return Fay$$_(Fay$$_(Fay$$cons)(x))(xs);});}` @user2407038 – S_FLUID May 07 '16 at 00:46
  • @S_FLUID This is very useful information (should be in the question!) - seems like `trainingData` is a function while you expect it to be a list. Again, how you produced this value is the source of your problem. – user2407038 May 07 '16 at 03:20

0 Answers0