News for hackers. Stuff that matters.
Re:Typed-Html: Type Checked JSX for Rust by dtolnay on Sunday November 18, 2018 @11:09PM (#18484169)
This library represents HTML in types. The <p> tag turns into a typed_html::elements::p [1], inside of which the attributes are held by a typed_html::elements::Attrs_p [2].

[1] https://docs.rs/typed-html/0.1.0/typed_html/elements/struct.... [2] https://docs.rs/typed-html/0.1.0/typed_html/elements/struct....

    let doc: DOMTree<String> = html!{
        <body>
          <img alt="xxx" />
          <p alt="xxx"></p>
        </body>
    };
If you try to give <p> an alt attribute, the program fails to compile.

    error[E0609]: no field `alt` on type `typed_html::elements::Attrs_p`
      --> src/main.rs:12:16
       |
    12 |             <p alt="xxx"></p>
       |                ^^^ unknown field
       |
       = note: available fields are: `accesskey`, `autocapitalize`, `class`, `contenteditable`, `contextmenu` ... and 9 others
Re:Typed-Html: Type Checked JSX for Rust by calebh on Monday November 19, 2018 @12:53AM (#18484457)
This solution bundles all of the attributes into the same type, which comes with the downside that it's impossible to represent a single attribute without also receiving all the other attributes.

I think that the best solution in Haskell would be to group the types in a typeclass. However then the typeclass is not directly associated with the p or img value constructors. I wonder if there is some way to use dependent types to improve this situation.

Re:Typed-Html: Type Checked JSX for Rust by err4nt on Monday November 19, 2018 @10:33AM (#18487086)
This is something that's very easy to check in a web browser with DOM - Suppose you have this HTML:

    <p>hello</p><img src=#>
If you try to access the `.alt` property of the <p> tag you get `undefined`, and if you try to access the `.alt` property of the <img> tag it returns the empty string in this case because the property exists on that tag, but hasn't been set to anything.