[Ur] C type for Ur/Web list type

Adam Chlipala adamc at csail.mit.edu
Thu Apr 14 07:24:17 EDT 2016


On 04/14/2016 07:14 AM, Artyom Shalkhakov wrote:
> 2016-04-14 17:02 GMT+06:00 Adam Chlipala <adamc at csail.mit.edu>:
>> On 04/14/2016 06:53 AM, Artyom Shalkhakov wrote:
>>> there is this question: what C types do [list string] and [option string]
>>> map to? I think that [option string] probably maps to a nullable pointer to
>>> uw_Basis_string. What about the list constructor?
>>
>> That's a tricky one.  There is actually no support for parametric
>> polymorphism in the FFI.  Every [list a] type is compiled to a separate C
>> struct.
>>
> Okay. The use-case is this: I'm decoding/encoding URI parameters in an
> Ur/Web program, naively. That involves a lot of string concatenation.
> Is there another (preferably external-dependency-free) approach to
> this?

Have you tried using normal Ur/Web code for that operation?  I think 
there's a nontrivial chance that you'll get better performance that way 
than with C FFI code, because the compiler has special optimizations for 
string concatenation.  They kick in when that concatenation flows 
directly into the value that is being returned as the HTTP body, whether 
it's HTML or a string in a blob.

It's probably possible to get those optimizations into play in other 
situations, too, with a moderate amount of compiler work.



More information about the Ur mailing list