I pondered the idea of how you create an MVC framework in Haskell in the form of WPF or AngularJS, but cannot find the key types or idea to get started. So, unfortunately, the vague question is - has anyone else thought about this issue?
I see the right lenses, the multi-plate and the composition, but I think that they all solve slightly different problems.
My sample example of how this will work:
- Create a model as a haskell simple data structure.
- Create a set of lenses or commands to modify your model.
- Write an HTML template (or any other) that is parameterized by types in the model.
.
data Model = Page { _title :: String, _content :: [(Int, String)] } title :: Lens Model String content :: Int -> Lens Model (Maybe String)
Then I would like to be able to write a function:
Model -> Template Model -> Html
and the function of updating parts of my view when using the lens.
Lens Model a -> a -> HtmlTemplate Model -> [(Path, Html)]
So, I think, the question is what type of lens will be that can work with one data structure and then be used to describe changes in another.
One possibility is to create a GADT that wraps all the lenses, and then generates HTML code like GADT, which can then be used to match the template at every step. eg.
data Lenses ab where Title :: Lens Model String -> Lenses Model String Item :: Lens Model String -> Lenses Model (Maybe String)
Then the data type of the Html template, for example.
data HtmlTemplate a = Text String | Element String [Attrib a] | forall b. Binding (Lenses ab) (Html b)
To which the Binding element can be mapped to the template directly.
But it looks like he almost defeats the point, because the model then joins the hips to look.
I wonder if anyone (smarter than me) has an idea of how this might work? Or even if it is a good idea?