2 ms·
What are the benefits of these monadic builder interfaces instead of simply pure functions? One can imagine a simple Html type with html tag functions e.g. `di
by CornCobs 5y ago
What are the benefits of these monadic builder interfaces instead of simply pure functions? One can imagine a simple Html type with html tag functions e.g.
`div :: [Attributes] -> [Html] -> Html`
Instead of using do notation to build up multiple children one would simply supply a list of children. Added benefit of using simpler map/filter/filterMap/mapMaybe vs their monadic counterparts
- louthy 5y agoYou can pass contextual state/environment in the monad for trivial data binding
- jaspervdj 5y agoThe builder interface has important performance benefits over working with lists: similar to e.g. concatenating many small Strings vs using StringBuilder in Java. The builder interface indeed does not need to be monadic, you can simply append things using <> and get the same benefits. The monadic interface is purely a syntactic enhancement on top of that, to reduce the number of operators you need.