Skip to content

Commit

Permalink
Add some information about faults.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Dec 27, 2024
1 parent fdeffa7 commit 46cec58
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/content/docs/Language Overview/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,16 @@ test(State.RUNNING); // Uses enum constant.

An [Optional type](/language-common/optionals-essential/#what-is-an-optional) is created by taking a type and appending `!`.
An Optional type behaves like a tagged union, containing either the
result or an Excuse of type [fault](#optional-excuses-are-of-type-fault).
result or an Excuse that is of a [fault](#optional-excuses-are-of-type-fault) type.

Once extracted, any specific fault can be converted to an `anyfault`.

```c3
int! i;
i = 5; // Assigning a real value to i.
i = IOResult.IO_ERROR?; // Assigning an optional result to i.
anyfault b = SearchError.MISSING;
b = @catch(i); // Assign the Excuse in i to b (IO_ERROR)
```

Only variables, expressions and function returns may be Optionals.
Expand All @@ -492,7 +496,8 @@ Read more about the Optional types on the page about [Optionals and error handli

### Optional Excuses are of type Fault

When an [Optional](/language-common/optionals-essential/#what-is-an-optional) does not contain a result, it is empty, and has an Excuse, which is of type `fault`.
When an [Optional](/language-common/optionals-essential/#what-is-an-optional) does not contain a result, it is empty, and has an Excuse, which is a`fault`.
The `anyfault` type may contain any such fault.

```c3
fault IOResult
Expand Down

0 comments on commit 46cec58

Please sign in to comment.