4 ms·
Look at this code which prints out an HTML tag: https://github.com/yawaramin/dream-html/blob/main/lib/dream_html.ml#L39 https://github.com/yawaramin/dream-html/
by yawaramin 4y ago
Look at this code which prints out an HTML tag: https://github.com/yawaramin/dream-html/blob/main/lib/dream_html.ml#L39 https://github.com/yawaramin/dream-html/blob/main/lib/dream_...
Initially you might think generating HTML tags from data structures in code should be a simple matter. But there are complexities--some tags are defined as having no child tags, others do. Some tags are purely character data (unstructured text), not structured data. Some are just comments. We need a way to compose multiple tags together into a single 'virtual' tag for flexible HTML generation. All these conditions can be pretty hard to keep track of--unless your compiler does exhaustiveness checking. Then the compiler will tell you if you missed any cases.
In the example above I didn't make any manual effort to cover all the cases, I simple listed out the cases I wanted to handle in order. The compiler made sure that I didn't miss any.
- never_inline 3y agoThis is very specific case though. Many times compiler tooling will do just fine with good old visitor patterns, enums etc.. Sure there may be small amount of errors missed, but that's not always as critical as availability of libraries and integration.