# 4.4.4-4 内置复合类型

除了基础类型之外，Go 语言规范中还定义了多种复合类型，编译器为每种类型都定义了对应的数据结构

## 4.4.4-4.1. 数组

数组类型（Array）的结构定义如下：

```go
type Array struct {
    len  int64
    elem Type
}
```

数组是定长的数据容器，所以除了元素类型之外，数组长度也是其类型中的组成部分，因此`[2]int`与`[3]int`虽然都是整型数组，但对类型系统而言，他们属于不同的类型。

## 4.4.4-4.2. 切片

切片类型（Slice）的结构定义如下：

```go
type Slice struct {
    elem Type
}
```

切片是变长的数据容器，其类型定义中不包括长度信息。

## 4.4.4-4.3. Map

Map 类型的结构定义如下：

```go
type Map struct {
    key, elem Type
}
```

其中`key`必须是可比较的数据类型（Comparable Type），后文中[类型的比较规则](/golang-bian-yi-qi-lei-xing-jian-cha/4.4.413-lei-xing-de-bi-jiao-gui-ze.md)有详细介绍。

## 4.4.4-4.4. Channel

Channel 类型的结构定义如下：

```go
type Chan struct {
    dir  ChanDir
    elem Type
}

// A ChanDir value indicates a channel direction.
type ChanDir int

// The direction of a channel is indicated by one of these constants.
const (
    SendRecv ChanDir = iota
    SendOnly
    RecvOnly
)
```

其中一个是 channel 的元素类型，一个是 channel 的数据流方向。

## 4.4.4-4.5. 指针

指针类型的结构定义如下：

```go
type Pointer struct {
    base Type // element type
}
```


---

# Agent Instructions: 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:

```
GET https://gocompiler.shizhz.me/golang-bian-yi-qi-lei-xing-jian-cha/4.4.44-nei-zhi-fu-he-lei-xing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
