3 ms·
sum types is not something supercritical, it saves few lines of code. Also, somehow I rarely have need to use something like that personally. > And ease of u
by riku_iki 4y ago
sum types is not something supercritical, it saves few lines of code.
Also, somehow I rarely have need to use something like that personally.
> And ease of use is important
the question is if insignificant syntax sugar worths switching to unpopular platform with undeveloped toolings and uncertain support.
- yawaramin 4y agoSum types save more than a few lines of code, they can save you from nasty bugs thanks to exhaustiveness checking in pattern matches. Once you get used to this you will be hard pressed to go back to prehistoric times.
- riku_iki 4y ago> Sum types save more than a few lines of code, they can save you from nasty bugs thanks to exhaustiveness checking in pattern matches. do you have specific example?
- yawaramin 4y agoLook 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 4y 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.