From ca530cf6124309c0ff492599833b6f1c897b9b2b Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 3 May 2025 16:06:53 +0200 Subject: [PATCH 1/2] document the tag decorator --- misc_docs/syntax/decorator_tag.mdx | 44 ++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 misc_docs/syntax/decorator_tag.mdx diff --git a/misc_docs/syntax/decorator_tag.mdx b/misc_docs/syntax/decorator_tag.mdx new file mode 100644 index 000000000..490af466c --- /dev/null +++ b/misc_docs/syntax/decorator_tag.mdx @@ -0,0 +1,44 @@ +--- +id: "tag-decorator" +keywords: ["tag", "decorator"] +name: "@tag" +summary: "This is the `@tag` decorator." +category: "decorators" +--- + +The `@tag` decorator is used to customize the discriminator for tagged variants. + + + +```res +type mood = Happy({level: int}) | Sad({level: int}) + +@tag("kind") +type mood2 = Happy({level: int}) | Sad({level: int}) + +let mood: mood = Happy({level: 10}) +let mood2: mood2 = Happy({level: 11}) + +``` + +```js +let mood = { + TAG: "Happy", + level: 10 +}; + +let mood2 = { + kind: "Happy", + level: 11 +}; +``` + + + +Notice the different discriminators in the JS output: `TAG` in `mood` vs `kind` in `mood2` + +Read more about [using `@tag` with variants](variant.md#tagged-variants). + +### References + +* [Using `@tag` with variants](variant.md#tagged-variants) From a20481280aa9952ea6b6fbb0c6f037e696a4e3bb Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Sat, 3 May 2025 16:09:39 +0200 Subject: [PATCH 2/2] dot --- misc_docs/syntax/decorator_tag.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc_docs/syntax/decorator_tag.mdx b/misc_docs/syntax/decorator_tag.mdx index 490af466c..8097ce849 100644 --- a/misc_docs/syntax/decorator_tag.mdx +++ b/misc_docs/syntax/decorator_tag.mdx @@ -35,7 +35,7 @@ let mood2 = { -Notice the different discriminators in the JS output: `TAG` in `mood` vs `kind` in `mood2` +Notice the different discriminators in the JS output: `TAG` in `mood` vs `kind` in `mood2`. Read more about [using `@tag` with variants](variant.md#tagged-variants).