Skip to content

Can we use free applicative functors for Flare? #3

@sharkdp

Description

@sharkdp

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:

  1. 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 [*].
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions