> For the complete documentation index, see [llms.txt](https://gauntletlang.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gauntletlang.gitbook.io/docs/advanced-features/tagged-unions.md).

# Tagged Unions

## Syntax

```fsharp
enum <TaggedUnionName> {
    case <case name>(<FieldName> : <FieldType>, ...) // case syntax
}
```

## Example

{% tabs %}
{% tab title="Gauntlet" %}

```fsharp
package main

import "fmt" as fmt
import "strconv" as strconv

enum Shapes {
    Circle(diameter: Int, color: String)
    Square(width: Int, height: Int, color: String)
    Triangle(base: Int, width: Int, height: Int, color: String)
}

fun main(): Unit {
    fmt.println("I only like red triangles. Let's see...")
    
    let myShape = Triangle(base: 10, width : 5, height : 20, color : "red")
    
    match myShape {
        case Triangle(base: let b, height: let height, color : "red") : {
            fmt.println("It's a red triangle with a height of " + strconv.itoa(height) + " and base length of " + strconv.itoa(b) + "!")
        }
        case Square(width : let width, color : "red") : {
            fmt.println("It's a red square with a width of " + strconv.itoa(width))
        }
        case Circle(diameter: let diameter, color : "red") : {
            fmt.println("It's a red circle with a diameter of " + strconv.itoa(diameter))
        }
    }
}
```

{% endtab %}

{% tab title="Transpiled" %}

```go
package main

import fmt "fmt"
import strconv "strconv"

type Case343818345 struct {
	diameter int
	color    string
}

type Case421059818 struct {
	width  int
	height int
	color  string
}

type Case499594069 struct {
	base   int
	width  int
	height int
	color  string
}

func main() {
	fmt.Println("I only like red triangles. Let's see...")
	myShape := map[int]any{499594069: Case499594069{base: 10, width: 5, height: 20, color: "red"}}
	if _, exists := myShape[499594069]; exists {

		if height, b := myShape[499594069].(Case499594069).height, myShape[499594069].(Case499594069).base; (func() bool {
			return (myShape[499594069].(Case499594069).base == (b)) && (myShape[499594069].(Case499594069).height == (height)) && (myShape[499594069].(Case499594069).color == ("red"))
		})() {
			fmt.Println("It's a red triangle with a height of " + strconv.Itoa(height) + " and base length of " + strconv.Itoa(b) + "!")
		}
	}
	if _, exists := myShape[421059818]; exists {

		if width := myShape[421059818].(Case421059818).width; (func() bool {
			return (myShape[421059818].(Case421059818).width == (width)) && (myShape[421059818].(Case421059818).color == ("red"))
		})() {
			fmt.Println("It's a red square with a width of " + strconv.Itoa(width))
		}
	}
	if _, exists := myShape[343818345]; exists {

		if diameter := myShape[343818345].(Case343818345).diameter; (func() bool {
			return (myShape[343818345].(Case343818345).diameter == (diameter)) && (myShape[343818345].(Case343818345).color == ("red"))
		})() {
			fmt.Println("It's a red circle with a diameter of " + strconv.Itoa(diameter))
		}
	}
	// Eliminates any 'unused variable' errors
	_ = myShape

}

```

{% endtab %}

{% tab title="Output" %}

```
I only like red shapes. Let's see if this shape is red...
It's a red triangle with a height of 20 and base length of 10
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gauntletlang.gitbook.io/docs/advanced-features/tagged-unions.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
