Skip to content

Commit

Permalink
feat: Add definition for data types
Browse files Browse the repository at this point in the history
  • Loading branch information
OJarrisonn committed May 30, 2024
1 parent 16bba4f commit 26d5cd5
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 7 deletions.
1 change: 0 additions & 1 deletion docs/aura.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
- [Data](./data.md)
- [Call](./call.md)
- [Control Flow](./flow.md)
- [Types](./type.md)
- [Tags](./tags.md)
- [Targets](./targets.md)
- [Roadmap](./roadmap.md)
105 changes: 99 additions & 6 deletions docs/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,115 @@

The way Aura treats data and memory depends on the target, but doesn't affect the result of the computation.

## AuraVM
## Targets

WIP

## C
### C

When targeting C there are three possibilities:

- Data is used only once, so it's moved
- Data is shared by reference when passed as arguments to calls
- Data is copied when passed as argument to data constructors

## JS
### JS

WIP

### HVM

WIP

## Immutability

The important thing to notice is: data is always immutable. So everytime you pass data to somewhere else, the original data is preserved
The important thing to notice is: data is always immutable. So everytime you pass data to somewhere else, the original data is preserved.

## Primitive Data Types

### Numbers

- `Int8`, `Int16`, `Int`/`Int32`, `Int64`: Signed integers
- `UInt8`, `UInt16`, `UInt`/`UInt32`, `UInt64`: Unsigned integers
- `Float`/`Float32`, `Float64`: floating point numbers

### Text

- `Char`: utf-8 char
- `String`: sequence of utf-8 chars

### Bool

- `Bool`

### Atom

- `Atom` `:[a-z]([a-z0-9]|-)*`: it is its own value

### Void

- `Void` `:null`

## Collection Types

### `Array(T)`

- A sequence of data of type T

### `List(T)`

- A linked list of type T

### `Object(T)`

- A sequence of data of type `T` indexed by `Atom`

### `Map(#eq, T)`

- A sequence of data of type `T` indexed by `#eq`

## Algebraic Data Types

### Enum: Sum type

Each variant is named after an Atom and may have associated data

```elixir
( T :variant-1 | :variant-2 | U :variant-2 )
```

### Struct: Product type

Each field is named after an Atom and must have a type

```elixir
( T :field-1, U :field-2, V :field-3 )
```

### Compound: Product type

```elixir
(T, U, V, W)
```

## Monads: computations wrapped by types

### `Nullable(T)`

Brings null-safety to Aura

- `:some(T)`: a non-null value
- `:null`: represents an empty value

### `Failable(T)`

Makes failures recoverable

- `:succ(T)`: the value that represents success
- `:fail(#failure)`: the value that represents a failure (a `#failure`)

### `Action(T)`

Wraps the result of `act` to encapsulate side effects

### `Async(T)`

Wraps the result of `async` to encapsulate assyncronous execution
Empty file removed docs/type.md
Empty file.
11 changes: 11 additions & 0 deletions examples/data.aura
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
link {println} = aura/io

type Number = (Int :int | Float :float)

main = act {
n = Number:int(10);

match n as
:int(i) => println(`Integer ${i}`),
:float(f) => println(`Float ${f}`);
}

0 comments on commit 26d5cd5

Please sign in to comment.