From 26d5cd548841ca14a95631a25cb8c617e42d4cce Mon Sep 17 00:00:00 2001 From: OJarrisonn Date: Thu, 30 May 2024 00:41:00 -0300 Subject: [PATCH] feat: Add definition for data types --- docs/aura.md | 1 - docs/data.md | 105 ++++++++++++++++++++++++++++++++++++++++++--- docs/type.md | 0 examples/data.aura | 11 +++++ 4 files changed, 110 insertions(+), 7 deletions(-) delete mode 100644 docs/type.md create mode 100644 examples/data.aura diff --git a/docs/aura.md b/docs/aura.md index 66e4d47..7fe53be 100644 --- a/docs/aura.md +++ b/docs/aura.md @@ -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) \ No newline at end of file diff --git a/docs/data.md b/docs/data.md index d7f668f..0d86af2 100644 --- a/docs/data.md +++ b/docs/data.md @@ -2,11 +2,9 @@ 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: @@ -14,10 +12,105 @@ When targeting C there are three possibilities: - 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 \ No newline at end of file +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 \ No newline at end of file diff --git a/docs/type.md b/docs/type.md deleted file mode 100644 index e69de29..0000000 diff --git a/examples/data.aura b/examples/data.aura new file mode 100644 index 0000000..6560805 --- /dev/null +++ b/examples/data.aura @@ -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}`); +} \ No newline at end of file