Foreign Store - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

Came across this interesting library:
https://hackage.haskell.org/package/foreign-store

Store a stable pointer in a foreign context to be retrieved later. Persists through GHCi reloads.

It is used in https://github.com/j-mueller/ghci-websockets (which is pretty cool)

A websocket server in GHCi that survives reloads. Contribute to j-mueller/ghci-websockets development by creating an account on GitHub.
Sridhar Ratnakumar

I'm currently playing with it to see if it would be useful to implement break-less hot-reloads across ghcid reboots in my upcoming static site generator: https://github.com/srid/ema

I use the foreign store to keep a TMVar of ws connection, but then I just realized that I need to somehow re-use the server thread too (across ghcid reboot)!

WIP: Static site generator that is change-aware. Contribute to srid/ema development by creating an account on GitHub.
Sridhar Ratnakumar

Would be happy to do pair programming on that ^^ right now

TheMatten

The upper one is horrifying, but the lower one is really cool :big_smile:

but then I just realized that I need to somehow re-use the server thread too (across ghcid reboot)!

I imagine some .pid file and separate process would work, with downside of making communication with it more complicated

Sridhar Ratnakumar

well, i'm using ghcid -T :main - so there is one process, but multiple threads may be forked (when haskell process exists, these threads won't be killed unless you clean them up manually)

Sridhar Ratnakumar

i currently use race_ to have them killed when ghcid reboots, but right now i'm thinking maybe I should leave them running, but store the threadid in foreign-store and establish a communication mechanism with them so the rebooted process can talk with them.

Sridhar Ratnakumar

the idea is that when you edit your blaze-html HTML DSL (or clay CSS DSL), and ghcid reloads the changed module and restarts main - the browser's websocket connection remains connected (so as to ensure a timely hot-reload)