More docs

This commit is contained in:
Micah Kendall 2022-11-25 17:34:22 +11:00 committed by Lucas
parent 77e3b57ff0
commit 7dc5392a81
10 changed files with 132 additions and 11 deletions

View File

@ -1,7 +1,7 @@
# Assert
```
assert rawdata is SomeType
```gleam
assert rawdata = SomeType
```
Causes the script to fail if the rawdata doesn't match the structure of datumtype

View File

@ -2,7 +2,7 @@
If statements
```
```gleam
if condition {
} else {
@ -12,7 +12,7 @@ if condition {
Case Patterns
```
```gleam
when color is {
Green -> "Success."
Blue -> "Warning."
@ -22,7 +22,7 @@ when color is {
Let bindings with blocks
```
```gleam
let num = -5
let absNum = if num>=0 {num} else {-num}

View File

@ -1,3 +1,19 @@
# Bool
Bools are True or False
Bools are True or False
There are logical conjunctions (True && True) or disjunctions (True || False).
```gleam
fn negate(b: Bool)->Bool {
if b {
False
}else{
True
}
}
fn and(b: Bool, c: Bool, d: Bool)->Bool{
b && c && d
}
```

View File

@ -1,6 +1,6 @@
# Comments
```
```gleam
// Line comments begin with a double-slash
/// Doc comments begin with a triple-slash

View File

@ -1 +1,8 @@
# Constants
Constants (not implemented yet) will be set in the global scope like so:
```gleam
const x = 1
```
Similar to a let binding, but with a const keyword instead.

View File

@ -5,7 +5,7 @@
Instantiation
```
```gleam
type Color {
Red
Blue
@ -18,7 +18,7 @@ Enum types can be thought of as the unit of product types.
Usage
```
```gleam
fn myFavouriteColor() -> Color {
Red
}
@ -26,14 +26,14 @@ fn myFavouriteColor() -> Color {
### Product Types
```
```gleam
type MyValue {
Name(String)
Age(Int)
}
```
```
```gleam
fn eitherNameOrAge(b: Bool) -> MyValue {
if b {
Name("James")

View File

@ -1 +1,43 @@
# Functions
Functions can be instantiated like so:
```gleam
fn f(x) {
}
```
l functions in aiken are pure without side effect, so all functions also must return some value.
A function with no return value (like above) will error.
Providing arg types:
```gleam
fn f(x: Int) {
}
```
and return types:
```gleam
fn f(x: Int) -> Int {
}
```
and the last value is implicitly returned:
```gleam
fn f(x: Int) -> Int {
x + 1
}
```
Functions can be made public in modules so they can be accessed by others
```gleam
pub fn myFunction(a: List(a)) {
// do something useful...
}
```
A

View File

@ -1 +1,15 @@
# Int
Ints are plutus integers which are arbitrary size.
So, there is no underflow. Basic arithmetic can be done for O(1) between ints (+,-,*).
```gleam
// A convenient helper function to get the number 7.
pub fn get7(){
let x = 3
let y = 2
let z = 1
x*y + z
}
```

View File

@ -1 +1,21 @@
# List
Aiken lists are plutus linked lists. Accessing by index is O(n). Appending or accessing head is O(1). Grabbing tail is O(1).
There is no builtin syntax for accessing by index as this is implemented by standard libs.
Accessing head, tail, or preceding elements can be done by pattern matching.
```gleam
// this function checks if a list has a sequence of 1 then 2 contained within it.
fn listStuff(a: List(Int)){
when a is {
[1,2, ..tail] -> True
[]->False
_ -> listStuff([2, ..tail])
}
}
```
Helper functions for safely accessing head, tail, are provided in standard lib but are implemented using comprehensions.
It is usually best to use your own comprehensions for efficiency (until the optimiser is better).

View File

@ -1 +1,23 @@
# Option
We define option as a generic type like so
```
pub type Option(a) {
None
Some(a)
}
```
Then, functions which fail may safely return an optional value.
```
pub fn getHead(a: List(a))->a {
when a is {
[a, .._]->Some(a)
[]->None
}
}
```
An unsafe variant of this function might instead assert that there is a head, and return it.