3 ms·
Yes, you can always generate a new union type for your return type and then pattern match on it. That is certainely better than C where you must use unsafe tagg
by smaddox 9y ago
Yes, you can always generate a new union type for your return type and then pattern match on it. That is certainely better than C where you must use unsafe tagged unions or void pointers. It is more verbose than in dynamic duck-typed languages, though I'll give you that it's quite compact in OCaml.
In a dependently typed language, you could reduce verbosity at the use site as well as avoid the extra runtime branch.
- tom_mellior 9y agoSo how exactly would you write the above five lines of OCaml in fewer than five lines in Idris?
- smaddox 9y agoThe verbosity is not in the function definition, its in the match expression needed at _every single call site_. In Idris, the definition would be similar length or longer, but call sites would not need a match expression.