<div dir="ltr"><div>Ah, so is this now why I'm getting this error?: TypeError: fr.f is not a function<br><br></div><div>Here's some screenshots of the code in the inspector: <a href="http://imgur.com/a/FBm3R">http://imgur.com/a/FBm3R</a><br></div><div><br></div><div>The code in question looks like this:<br><br>function new_map_with (init) {<br> var acc = new Map ();<br> var curr = init;<br> while (curr._2 != null) {<br> acc.set (curr._1._1, curr._1._2);<br> curr = curr._2;}<br> //curr._1._1 contains the last elem when curr._1._2 === null.<br> acc.set (curr._1._1, curr._1._2);<br> return acc;}<br></div><div><br></div>I am attempting to pass back the Map from JS back to Ur, and it seems that fr.f at runtime will hold new_map_with at first, then after it executes it then holds the Map I generates. At that point line 1991 gets called e = {c: "c", v: fr.f(v)}; and I get that error, since fr.f now holds Map {...} and Map isn't a function..<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 22, 2017 at 4:42 AM, Adam Chlipala <span dir="ltr"><<a href="mailto:adamc@csail.mit.edu" target="_blank">adamc@csail.mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div class="m_-170248232430822086moz-cite-prefix">I can confirm that
non-primitive/abstract types are not meant to cross the FFI
boundary.<div><div class="h5"><br>
<br>
On 05/21/2017 11:31 PM, Aistis Raulinaitis wrote:<br>
</div></div></div><div><div class="h5">
<blockquote type="cite">
<div dir="ltr">Thanks!<br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Sun, May 21, 2017 at 8:27 PM, Artyom
Shalkhakov <span dir="ltr"><<a href="mailto:artyom.shalkhakov@gmail.com" target="_blank">artyom.shalkhakov@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>2017-05-22 9:19 GMT+06:00 Aistis Raulinaitis <<a href="mailto:sheganinans@gmail.com" target="_blank">sheganinans@gmail.com</a>>:<br>
> Hmm, that makes sense. Do you have an example of FFI
with an abstract type?<br>
> I tried to encapsulate the map type with a con, but
obviously that does not<br>
> work..<br>
><br>
<br>
</span>Sure, here are two examples:<br>
<br>
<a href="https://github.com/bbarenblat/urweb-regex" rel="noreferrer" target="_blank">https://github.com/bbarenblat/<wbr>urweb-regex</a>
(in particular, take a look<br>
at regex__FFI.urs and the two types [substring_t] and<br>
[substring_list_t])<br>
<a href="https://github.com/ashalkhakov/urweb-storage" rel="noreferrer" target="_blank">https://github.com/ashalkhakov<wbr>/urweb-storage</a>
(shameless plug; in<br>
particular, take a look at storage__FFI.urs and the type
[storage])<br>
<div class="m_-170248232430822086HOEnZb">
<div class="m_-170248232430822086h5"><br>
> On Sun, May 21, 2017 at 8:10 PM, Artyom Shalkhakov<br>
> <<a href="mailto:artyom.shalkhakov@gmail.com" target="_blank">artyom.shalkhakov@gmail.com</a>>
wrote:<br>
>><br>
>> 2017-05-22 6:22 GMT+06:00 Aistis Raulinaitis
<<a href="mailto:sheganinans@gmail.com" target="_blank">sheganinans@gmail.com</a>>:<br>
>> > So I am working with the JS FFI, however
it seems that the clientOnly<br>
>> > directive is being ignored.<br>
>> ><br>
>> > Here is the example code:<br>
>> ><br>
>> > ~~~<br>
>> > main.urp:<br>
>> > ~~~<br>
>> ><br>
>> > ffi js_map<br>
>> > jsFunc Js_map.new_map=new_map<br>
>> > jsFunc Js_map.new_map_with=new_map_wi<wbr>th<br>
>> > clientOnly Js_map.new_map<br>
>> > clientOnly Js_map.new_map_with<br>
>> > benignEffectful Js_map.new_map<br>
>> > benignEffectful Js_map.new_map_with<br>
>> > jsFile js_map.js<br>
>> ><br>
>> > main<br>
>> ><br>
>> ><br>
>> > ~~~<br>
>> > main.urs:<br>
>> > ~~~<br>
>> ><br>
>> > val main : unit -> transaction page<br>
>> ><br>
>> ><br>
>> > ~~~<br>
>> > main.ur:<br>
>> > ~~~<br>
>> ><br>
>> > fun main () =<br>
>> > c <- Js_map.new_map_with ((1,
2)::[]);<br>
>> > return <xml></xml><br>
>> ><br>
>> ><br>
>> > ~~~<br>
>> > js_map.urs:<br>
>> > ~~~<br>
>> ><br>
>> > con js_map :: Type -> Type -> Type<br>
>> ><br>
>> > val new_map : k ::: Type -> v :::
Type -> unit -> transaction<br>
>> > (js_map k<br>
>> > v)<br>
>> > val new_map_with : k ::: Type -> v :::
Type -> list (k * v) -><br>
>> > transaction<br>
>> > (js_map k v)<br>
>> ><br>
>> ><br>
>> > ~~~<br>
>> > js_map.js:<br>
>> > ~~~<br>
>> ><br>
>> > function new_map () {return new Map ();}<br>
>> ><br>
>> > function new_map_with (arg) {return new
Map (arg); }<br>
>> ><br>
>> ><br>
>> > ~~~<br>
>> > So in main.ur, you can see that I am
calling this Js code in a C<br>
>> > context,<br>
>> > instead of getting an error complaining
about how it should be called on<br>
>> > the<br>
>> > client, instead I get this confusing
error:<br>
>> ><br>
>> > urweb main<br>
>> > /Users/ace/src/cli_only/js_map<wbr>.urs:4:75:
(to 4:87) Unsupported type<br>
>> > constructor<br>
>> > Constructor: FFI(Js_map.js_map_with)
FFI(Basis.int) FFI(Basis.int)<br>
>> > /usr/local/Cellar/urweb/201701<wbr>05/lib/urweb/ur/basis.urs:127:<wbr>23:
(to<br>
>> > 127:25)<br>
>> > Unsupported type constructor<br>
>> > Constructor: FFI(Js_map.js_map_with)
FFI(Basis.int) FFI(Basis.int)<br>
>> > make: *** [all] Error 1<br>
>> ><br>
>><br>
>> I got the impression that Ur/Web being a
whole-program optimizing<br>
>> compiler, the only types being supported for
marshalling between FFI<br>
>> code and non-FFI code are primitive types and
abstract types. I think<br>
>> I asked this same question some time ago.<br>
>><br>
>> So it looks like you will have to work around
this somehow.<br>
>><br>
>> ><br>
>> ><br>
>> > ______________________________<wbr>_________________<br>
>> > Ur mailing list<br>
>> > <a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
>> > <a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/c<wbr>gi-bin/mailman/listinfo/ur</a><br>
>> ><br>
>><br>
>><br>
>><br>
>> --<br>
>> Cheers,<br>
>> Artyom Shalkhakov<br>
>><br>
>> ______________________________<wbr>_________________<br>
>> Ur mailing list<br>
>> <a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
>> <a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/c<wbr>gi-bin/mailman/listinfo/ur</a><br>
><br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> Ur mailing list<br>
> <a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
> <a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/c<wbr>gi-bin/mailman/listinfo/ur</a><br>
><br>
<br>
<br>
<br>
--<br>
Cheers,<br>
Artyom Shalkhakov<br>
<br>
______________________________<wbr>_________________<br>
Ur mailing list<br>
<a href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a><br>
<a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/c<wbr>gi-bin/mailman/listinfo/ur</a><br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="m_-170248232430822086mimeAttachmentHeader"></fieldset>
<br>
<pre>______________________________<wbr>_________________
Ur mailing list
<a class="m_-170248232430822086moz-txt-link-abbreviated" href="mailto:Ur@impredicative.com" target="_blank">Ur@impredicative.com</a>
<a class="m_-170248232430822086moz-txt-link-freetext" href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" target="_blank">http://www.impredicative.com/<wbr>cgi-bin/mailman/listinfo/ur</a>
</pre>
</blockquote>
<p><br>
</p>
</div></div></div>
<br>______________________________<wbr>_________________<br>
Ur mailing list<br>
<a href="mailto:Ur@impredicative.com">Ur@impredicative.com</a><br>
<a href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur" rel="noreferrer" target="_blank">http://www.impredicative.com/<wbr>cgi-bin/mailman/listinfo/ur</a><br>
<br></blockquote></div><br></div>