Skip to content

Commit

Permalink
Mention the new type system in typespecs doc (#14188)
Browse files Browse the repository at this point in the history
sabiwara committed Jan 15, 2025
1 parent 88c75bc commit 4def31f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/elixir/pages/references/typespecs.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Typespecs reference

Elixir comes with a notation for declaring types and specifications. This document is a
reference into their uses and syntax.
> #### Typespecs are not set-theoretic types {: .warning}
>
> Elixir is in the process of implementing its
> [own type system](./gradual-set-theoretic-types.md) based on set-theoretic types.
> Typespecs, which are described in the following document, are a distinct notation
> for declaring types and specifications based on Erlang.
> Typespecs may be phased out as the set-theoretic type effort moves forward.
Elixir is a dynamically typed language, and as such, type specifications are never used by the compiler to optimize or modify code. Still, using type specifications is useful because:

@@ -48,6 +53,13 @@ The syntax Elixir provides for type specifications is similar to [the one in Erl

The notation to represent the union of types is the pipe `|`. For example, the typespec `type :: atom() | pid() | tuple()` creates a type `type` that can be either an `atom`, a `pid`, or a `tuple`. This is usually called a [sum type](https://en.wikipedia.org/wiki/Tagged_union) in other languages

> #### Differences with set-theoretic types {: .warning}
>
> While they do share some similarities, the types below do not map one-to-one
> to the new types from the set theoretic type system.
> For example, there is no plan to support subsets of the `integer()` type such
> as positive, ranges or literals.
### Basic types

type ::

0 comments on commit 4def31f

Please sign in to comment.