Skip to content

Comment on Virtual DOM in Elm

Comments

All of the empty brackets to describe the virtual DOM looks bad to me. I'm curious if this is regarded as a language smell.

It's easy to use partial application to get rid of that problem: the type of the function node is:

  node : String -> [Attribute] -> [CssProperty] -> [Html] -> Html
We could define a convenient function div, for example, with
  div : [Attribute] - > [CssProperty] -> [Html] -> Html
  div = node "div"
that would let us say "div [] [] [text "Hello world"]" instead of "node "div" [] [] [text "Hello world"]". Of course, this doesn't fix your problem with the empty brackets. This can be fixed with something like:
  bareDiv : [Html] -> Html
  bareDiv = div [] []
letting us do "bareDiv [text "Hello world"]"
AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.