Best effect for an FFI function that sets internal state

40 views
Skip to first unread message

rvdalen

unread,
Jul 25, 2017, 5:04:07 AM7/25/17
to purescript
 Hi everyone,

I am still busy with wrapping the Mithril library for use in PureScript.

There is a function called `route()` which takes some arguments and does not return any value.
It sets some internal state on some global object .

I am not sure if there is an existing effect in PureScript that is used to represent this.
I was thinking of using the `ST` effect for this.
Just wanted to know if `ST` effect is fine or if I should rather use some other effect that better describes what the `route()` function does?

Regards
--Rouan

Harry Garrood

unread,
Jul 25, 2017, 8:28:47 AM7/25/17
to pures...@googlegroups.com
Hi Rouan,

I think ST might not quite be what you want, because ST is for mutation of local state - in particular any mutation in ST should not be observable outside ST (normally the type system guarantees this to be the case but if you're using the FFI for bindings to a library it's easy to accidentally invalidate that).

If you're mutating `window` the DOM effect might be appropriate, or you can also define your own effect.

Cheers
Harry
> --
> You received this message because you are subscribed to the Google Groups
> "purescript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> For more options, visit https://groups.google.com/d/optout.

rvdalen

unread,
Jul 25, 2017, 8:38:52 AM7/25/17
to purescript
Hi Harry,

I had a hunch that ST is not exactly what I needed.
I will give this some more thought.  I am leaning more towards
maybe having a `Mithril` effect.

Are there any guidelines for effects when one starts thinking abut creating
custom effects?

Regards
--Rouan

Harry Garrood

unread,
Jul 26, 2017, 3:49:10 PM7/26/17
to pures...@googlegroups.com
I'm not aware of any such guidelines. It sounds like defining an effect
might be the right way to go for you though, it's often the case that
you will want to define an effect if you're wrapping a JS library.

Harry
Reply all
Reply to author
Forward
0 new messages