<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">I can confirm that
non-primitive/abstract types are not meant to cross the FFI
boundary.<br>
<br>
On 05/21/2017 11:31 PM, Aistis Raulinaitis wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAKzB5bXUSwgGiaZkGFPrWquf9NNHD+jvzPtgGehsY7gBZb1m8Q@mail.gmail.com">
<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"
moz-do-not-send="true">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
class="">2017-05-22 9:19 GMT+06:00 Aistis Raulinaitis <<a
href="mailto:sheganinans@gmail.com"
moz-do-not-send="true">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" moz-do-not-send="true">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" moz-do-not-send="true">https://github.com/<wbr>ashalkhakov/urweb-storage</a>
(shameless plug; in<br>
particular, take a look at storage__FFI.urs and the type
[storage])<br>
<div class="HOEnZb">
<div class="h5"><br>
> On Sun, May 21, 2017 at 8:10 PM, Artyom Shalkhakov<br>
> <<a href="mailto:artyom.shalkhakov@gmail.com"
moz-do-not-send="true">artyom.shalkhakov@gmail.com</a>>
wrote:<br>
>><br>
>> 2017-05-22 6:22 GMT+06:00 Aistis Raulinaitis
<<a href="mailto:sheganinans@gmail.com"
moz-do-not-send="true">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_<wbr>with<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_<wbr>map.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/<wbr>20170105/lib/urweb/ur/basis.<wbr>urs:127: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"
moz-do-not-send="true">Ur@impredicative.com</a><br>
>> > <a
href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur"
rel="noreferrer" target="_blank"
moz-do-not-send="true">http://www.impredicative.com/<wbr>cgi-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"
moz-do-not-send="true">Ur@impredicative.com</a><br>
>> <a
href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur"
rel="noreferrer" target="_blank"
moz-do-not-send="true">http://www.impredicative.com/<wbr>cgi-bin/mailman/listinfo/ur</a><br>
><br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> Ur mailing list<br>
> <a href="mailto:Ur@impredicative.com"
moz-do-not-send="true">Ur@impredicative.com</a><br>
> <a
href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur"
rel="noreferrer" target="_blank"
moz-do-not-send="true">http://www.impredicative.com/<wbr>cgi-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"
moz-do-not-send="true">Ur@impredicative.com</a><br>
<a
href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur"
rel="noreferrer" target="_blank"
moz-do-not-send="true">http://www.impredicative.com/<wbr>cgi-bin/mailman/listinfo/ur</a><br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Ur mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Ur@impredicative.com">Ur@impredicative.com</a>
<a class="moz-txt-link-freetext" href="http://www.impredicative.com/cgi-bin/mailman/listinfo/ur">http://www.impredicative.com/cgi-bin/mailman/listinfo/ur</a>
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>