[Ur] runST monad in ur/web

Ziv Scully ziv at mit.edu
Tue Dec 29 12:48:07 EST 2015


The short answer is to use the FFI to do the relevant computation in
another language. C is the easiest choice to get working, but Edward Yang's
Logitext sets up Haskell for this. You're then free to give the function a
non-transaction type.

It might be possible to write the ST monad using the FFI. One can implement
types and functions for references, arrays, etc. in C, use .urp
declarations mark all these functions as effectful, and wrap these types
and functions in a module that enforces the typical ST types, which is
straightforward with Ur/Web's rank-N types. That said, the lack of garbage
collection could make this complicated. I'm not sure how safe it is to
store Ur/Web structures in references (the structure might get freed) or
how to free any allocated ST structures. The first problem has an easy
half-solution: if there are some types that are safely usable in ST
references, use a closed type class to enumerate them. (See the interface
for Basis.sql_injectable for a similar example.)


On Tuesday, December 29, 2015, Adam Chlipala <adamc at csail.mit.edu> wrote:

> I wonder if this source file would be of interest, from Sergey Mironov's
> urweb-monad-pack library.
>     https://github.com/grwlf/urweb-monad-pack/blob/master/state.ur
>
> I'm not familiar enough with Haskell myself to know whether it's a perfect
> match.
>
> On 12/23/2015 11:16 AM, Artella Coding wrote:
>
>> Hi, is there something like a haskell runST monad (
>> https://wiki.haskell.org/Monad/ST) in ur/web, so that I can perform
>> mutations within a pure function?
>>
>> For example I might want to have my pure function make a copy of a large
>> array, and then perform the relevant mutations on this copy, before
>> returning this copy. The function is pure in that it does not modify the
>> input nor does it require data from the "outside world", and yet relies on
>> mutations of the internal copy (which it employs for the sake of
>> efficiency).
>>
>
> _______________________________________________
> Ur mailing list
> Ur at impredicative.com
> http://www.impredicative.com/cgi-bin/mailman/listinfo/ur
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20151229/58695804/attachment.html>


More information about the Ur mailing list