Right now, we use the 'effectful' type
newtype UI e a = UI (Eff (dom :: DOM, chan :: Chan | e) (Flare a))
as our main applicative functor to create the user interfaces. Here, Flare is defined as
data Flare a = Flare (Array Element) (Signal a)
It seems unnecessary that we have to include the effects at this stage already. It would be much nicer to work with a 'pure' data type similar to Flare and only introduce the effects when actually running the UI (Flare itself is also an applicative functor).
My initial thinking was that it is necessary to include the effects, because we have to construct the HTML Elements (DOM) and set up the channels for the corresponding signals (Chan). It was very easy to do these things inside the Eff monad.
But if we are able to defer the actual setup, we could get rid of the effects. This would involve two things:
- An ADT for
Element which simply remembers the components which we have to set up (something like data Element = InputInt Label Int | InputBool Label Bool | .. which stores the label and default values). This is the easy part [*].
- A structure which remembers the transformations to the actual data (
maps and applys).
@paf31 @ethul: I'm not experienced enough to see this right away, but if one of you has some free time to have a short look, this would be great. My idea was that free applicative functors from purescript-freeap could actually be a good fit for point 2. As far as I understand, the free applicative functor 'remembers' all the transformations and I could run it via foldFreeAp at the point when I actually want to set up the UI (via a natural transformation from Flare to Signal??).
[*] Actually, this would make things like #2 much simpler to implement.
Right now, we use the 'effectful' type
as our main applicative functor to create the user interfaces. Here,
Flareis defined asIt seems unnecessary that we have to include the effects at this stage already. It would be much nicer to work with a 'pure' data type similar to
Flareand only introduce the effects when actually running the UI (Flareitself is also an applicative functor).My initial thinking was that it is necessary to include the effects, because we have to construct the HTML Elements (
DOM) and set up the channels for the corresponding signals (Chan). It was very easy to do these things inside theEffmonad.But if we are able to defer the actual setup, we could get rid of the effects. This would involve two things:
Elementwhich simply remembers the components which we have to set up (something likedata Element = InputInt Label Int | InputBool Label Bool | ..which stores the label and default values). This is the easy part [*].maps andapplys).@paf31 @ethul: I'm not experienced enough to see this right away, but if one of you has some free time to have a short look, this would be great. My idea was that free applicative functors from purescript-freeap could actually be a good fit for point 2. As far as I understand, the free applicative functor 'remembers' all the transformations and I could run it via
foldFreeApat the point when I actually want to set up the UI (via a natural transformation fromFlaretoSignal??).[*] Actually, this would make things like #2 much simpler to implement.