Nim (programming language): Difference between revisions

Content deleted Content added
No edit summary
Cpbotha (talk | contribs)
m idiomatic English here for something that is left to some other aspect is "relegated" not "regulated"
Line 487:
 
==== Algebraic data types and pattern matching ====
Nim has support for [[Product type|product types]] via the <code>object</code> type, and for [[Sum type|sum types]] via [[Variant type|object variants]]: raw representations of [[Tagged union|tagged unions]], with an enumerated type tag that must be [[Pattern matching|safely matched upon]] before fields of variants can be accessed.<ref>{{Cite web |title=Nim Manual: Object variants |url=https://nim-lang.org/docs/manual.html#types-object-variants |access-date=2023-08-17 |website=nim-lang.org}}</ref> These types can be [[Algebraic data type|composed algebraically]]. [[Structural pattern matching]] is available, but regulatedrelegated to macros in various third-party libraries.<ref>{{Cite web |title=src/fusion/matching |url=https://nim-lang.github.io/fusion/src/fusion/matching.html |access-date=2023-08-17 |website=nim-lang.github.io}}</ref><syntaxhighlight lang="nim">
import std/tables