9 ms·
Are algebraic data types and pattern matching possible in Nim? Googling shows that there are libraries (https://github.com/andreaferretti/patty https://github.c
by zinclozenge 8y ago
Are algebraic data types and pattern matching possible in Nim? Googling shows that there are libraries (https://github.com/andreaferretti/patty https://github.com/andreaferretti/patty for example) but basically amounts to deferring their implementation by way of the macro system/metaprogramming.
- beagle3 8y agoThe pattern matching story has not reached a conclusion, though it is getting there slowly. But that’s an important Nim philosophy - do not put into the language things if you can efficiently and nice-syntaxly implement them in a library. Once pattern matching is sufficiently mature - if it is too slow as a macro library, or the syntax too cumbersome - it will likely find its way to a core language feature. But if it’s good enough, it will stay a library (possibly, but not necessarily, part of the standard library); why burden the language?
- alehander42 8y agoAlgebraic data types are everywhere in Nim code: they are just called case objects(and they do have some differences compared to e.g. haskell, but often they are used in a similar way) There is also https://github.com/krux02/ast-pattern-matching https://github.com/krux02/ast-pattern-matching (optimized for usage in macros / metaprogramming) Yes: they all use the macro system, but this is a good thin IMO: it's better to leave the core language simpler and to build such abstractions on top of it.