JSON instance for effects - Polysemy

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

Sridhar Ratnakumar

How would one go about writing JSON instances for the effect GADTs? My intention is to share these GADTs with the ghcjs frontend, and send the JSON blob directly from the frontend in order to have the backend effectuate the requested effect.

Sridhar Ratnakumar

I suppose I could use aeson-gadt-th if I make m ~ Identity

TheMatten

That m is Sem r when being used, we mostly just avoid cyclic dependency on r in types this way - that's not problem for first-order effects (where m is phantom), but for higher-order effects you would have to make sure m as it carries have m matching with Sem r on the other side

TheMatten

That is, if your effects are first-order, Identity should work - but otherwise it won't

Torsten Schmits

are you using polysemy in the frontend?

Sridhar Ratnakumar

Only in the backend, but I'm thinking of using the non-monadic GADT type in the frontend. (so makeSem would create orphan instances in the backend)

Sridhar Ratnakumar

This is all in the context of obelisk prerendering. I think it would be cool if in this otherwise SPA app (pulling DB data from xhr requests), the backend would prerender the DB data, for google juice.

Sridhar Ratnakumar

So the polymorphic code when run from frontend would go via xhr, but when run from backend (during prerendering) would talk directly to the database. The "API" is captured by a polysemy effect GADT.