> 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/structs.md).

# Structs

## Struct Declaration Syntax

```fsharp
[export] struct <StructName>[Generics] {
  [export] <FieldName>: <FieldType> [`FieldTag`] // Syntax of fields
  <EmbeddedInterfaces> // Syntax of embedded interfaces
  <EmbeddedStructs> // Syntax of embedded structs
}
```

For syntax of `Generics` - [Read before Proceeding](/docs/read-before-proceeding.md#common-placeholders-throughout-documentation)

## Struct Construction

```fsharp
<StructName>[GenericsInstantiation]{Field1 = Value1, etc}
```

## Working Example

{% hint style="info" %}
Embedded fields can only be accessed off of the embedded type. They are not a part of the "overall" type. For instance, if `B` with field `C` is embedded into `A`, then `C` can only be accessed by `A.B.C`, not `A.C`.
{% endhint %}

{% hint style="info" %}
While generics were not needed in this specific example, they were used to showcase syntax&#x20;
{% endhint %}

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

```fsharp
package main

import "fmt" as fmt
import "golang.org/x/exp/constraints" as constraints

struct BankAccount[T : constraints.Integer] {
  Retirement: T 
  Checking: T
  Total: T
}

struct Human[T: constraints.Integer] {
  export FullName: String
  export Age: Int
  BankAccount[T]
}


fun main(): Unit {
  let age = 28
  let firstName = "John"
  let lastName = "Doe"
  let fullName = firstName + " " + lastName
  let john = Human[Int]{FullName = fullName, Age = age, BankAccount = BankAccount[Int]{Retirement = 100000, Checking = 1000, Total = 100000 + 1000}}
  fmt.println("John's full name is:")
  fmt.println(john.FullName)
  fmt.println("In total, he has this much money:")
  fmt.println(john.BankAccount.Total)

}
```

{% endtab %}

{% tab title="Transpiled" %}

```go
package main

import fmt "fmt"
import constraints "golang.org/x/exp/constraints"

type bankAccount[T constraints.Integer] struct {
	total      T
	checking   T
	retirement T
}

type human[T constraints.Integer] struct {
	Age      int
	FullName string

	bankAccount[T]
}

func main() {
	age := 28
	firstName := "John"
	lastName := "Doe"
	fullName := firstName + " " + lastName
	john := human[int]{FullName: fullName, Age: age, bankAccount: bankAccount[int]{retirement: 100000, checking: 1000, total: 100000 + 1000}}
	fmt.Println("John's full name is:")
	fmt.Println(john.FullName)
	fmt.Println("In total, he has this much money:")
	fmt.Println(john.bankAccount.total)
	// Eliminates any 'unused variable' errors
	_, _, _, _, _ = age, firstName, fullName, john, lastName

}

```

{% endtab %}

{% tab title="Output" %}

```
John's full name is:
John Doe
In total, he has this much money:
101000
```

{% 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gauntletlang.gitbook.io/docs/structs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
