[Ur] Confusing error message when using effectful javascript ffi function in onload handler

Adam Chlipala adamc at csail.mit.edu
Fri Jun 14 12:53:10 EDT 2013


I agree that it would be nice to get the proper source location 
information propagated into that error message.  However, I don't think 
the message itself is so misleading.  Presumably your 'onload' handler 
is on a page that can be reached via a GET request to a link.  The HTTP 
standard or some related advice specifies that GET requests should not 
have side effects, and Ur/Web is detecting that your [Js.init] function 
might actually cause a side effect upon loading of the link.  From a 
user's perspective, there is little practical difference between 
"fetching URL causes a side effect" and "fetching URL returns a page 
whose JavaScript immediately causes a side effect."

I hope the Ur/Web manual makes clear that 'benignEffectful' is for 
functions with only page-local side effects, while 'effectful' is for 
functions that may cause persistent side effects.  Does your [Js.init] 
really belong in the second category?  If so, then the compiler seems to 
me to be making a reasonable inference that you aren't following the 
rules about GET requests not causing persistent side effects.

On 06/13/2013 08:14 PM, Daniel Patterson wrote:
> I have an ffi function declared like:
>
> ffi js
> jsFunc Js.init=init
> effectful Js.init
>
> I have it in my body onload handler as:
>
> Js.init ...
>
> And the error that it produces is:
>
> :0:0: (to 0:0) A link () could cause side effects; try implementing it
> with a form instead
> make: *** [app] Error 1
>
>
> Which is confusing because:
>
> a. it has no source location information, so I have no idea where the
> error is occuring and
>
> b. it is not caused by a link.
>
> The problem goes away if I either don't say that it is effectful, or
> say it is benignEffectful, but I'm not sure why this is - because it
> seems like onload handlers should be able to cause effects...
>    



More information about the Ur mailing list