concurrency and iQuery

50 views
Skip to first unread message

Jeremy Shaw

unread,
Aug 9, 2014, 12:04:57 AM8/9/14
to idris...@googlegroups.com
Hello!

I was playing around with iQuery and quickly ran into the concurrency
issue. I can create fancy data types for my Model and manipulate the
data to my hearts content in the main function. But to actually get
input from the user, I need to register some callback functions using
things like:

onClick : Element -> (Event -> IO Int) -> IO ()

That type is pretty much imposed on us by the browser -- so there is
no getting around that. The problem is that this callback has no way
to mutate the Model that I constructed in my main function. What I
need is an IORef or something. ghcjs seems to use MVar, and fay has
some sort of Ref thing that is like an IORef. (And in javascript, you
just have global variables, AFAIK).

I see that there is a IQuery.State -- but that only allows storing
very primitive values.

A grep of the idris source seems to indicate that
System.Concurrency.Process is not implemented by the javascript
backend as I could find no references to idris_sendMessage outside of
the C RTS.

Is there a plan for what this will look like in the future?

As a side note, the repository name is iQuery, the module prefix is
IQuery, but the package name iquery -- would it be possible to unify
the capitalization scheme?

- jeremy

Jürgen Peters

unread,
Aug 10, 2014, 4:41:00 AM8/10/14
to idris...@googlegroups.com
Am Sa, 9.08.2014, 06:04, schrieb Jeremy Shaw:
>
> (And in javascript, you
> just have global variables, AFAIK).

Variables are global by default. But you can initialize a variable with
"var" and then it becomes local to the lexical scope it was defined in.

> I see that there is a IQuery.State -- but that only allows storing
> very primitive values.

The way I've built IQuery.State you have to specifically implement each
data type into the module. I have currently no time or motivation to
enhance the module myself, but that shouldn't stop you to do that if you
so desire.

You would have to add a value to StateTy and expand the functions
interpSTy (trivial), fromState' and toState (slightly more complicated) to
do so.

> A grep of the idris source seems to indicate that
> System.Concurrency.Process is not implemented by the javascript
> backend as I could find no references to idris_sendMessage outside of
> the C RTS.
>
> Is there a plan for what this will look like in the future?

As much as some do like the idea of having proper concurrency support in
JS, afaik no one is currently working on that.


Br,
tauli


Jeremy Shaw

unread,
Aug 11, 2014, 6:06:16 PM8/11/14
to idris...@googlegroups.com
For my particular needs I was able to exploit the FFI to create global
variables:

putModel : Model -> IO ()
putModel model =
mkForeign (FFun "model = %0" [FAny Model] FUnit) model

getModel : IO Model
getModel =
mkForeign (FFun "model" [] (FAny Model))

Thanks to Melvar on #idris for the suggestion.

- jeremy
Reply all
Reply to author
Forward
0 new messages