---
title: Std.Generic
---

Generic representation building blocks for user-extensible derives.
See docs/planning/user-extensible-derives.md.

## Types

### U1

```saga
type U1 =
  | U1
```

The unit shape — represents zero fields / a nullary constructor.

### Leaf

```saga
type Leaf a =
  | Leaf a
```

A single field, holding a value of type `a`.

### Labeled

```saga
type Labeled (n : Symbol) a =
  | Labeled a
```

A named field. The name lives at the type level as a `Symbol`-kinded
parameter — library impls recover the string via `KnownSymbol`.

### And

```saga
type And l r =
  | And l r
```

A product (two-or-more fields are right-leaning chains of And).

### Or

```saga
type Or l r =
  | Or_Left l
  | Or_Right r
```

A sum (two-or-more variants are right-leaning chains of Or).

### Variant

```saga
type Variant (n : Symbol) a =
  | Variant a
```

A sum constructor. The constructor name lives at the type level as a
`Symbol`-kinded parameter — library impls recover the string via
`KnownSymbol`. Distinguishes constructor labels from record-field
labels (Labeled).

### Record

```saga
type Record a =
  | Record String a
```

Top-level framing wrapper for records: runtime type name + inner shape.
Gives library codecs a hook for outer framing (e.g. JSON object braces).

### Adt

```saga
type Adt a =
  | Adt String a
```

Top-level framing wrapper for ADTs: runtime type name + variant tree.
Gives library codecs a hook for outer framing distinct from records.

## Traits

### Generic

```saga
trait Generic a r {
  fun to : a -> r
  fun from : r -> a
}
```

Isomorphism between a user type `a` and its structural representation `r`.
The first parameter functionally determines the second (coherence rule).

