basic docs

This commit is contained in:
Micah Kendall 2022-11-24 08:23:46 +11:00 committed by Lucas
parent d5087dbcc7
commit 77e3b57ff0
6 changed files with 115 additions and 0 deletions

View File

@ -1 +1,10 @@
# Assert
```
assert rawdata is SomeType
```
Causes the script to fail if the rawdata doesn't match the structure of datumtype
Otherwise, returns a value of SomeType
Primarily for validating input datums / redeemers.

View File

@ -1 +1,36 @@
# Blocks
If statements
```
if condition {
} else {
}
```
Case Patterns
```
when color is {
Green -> "Success."
Blue -> "Warning."
Red -> "Error!"
}
```
Let bindings with blocks
```
let num = -5
let absNum = if num>=0 {num} else {-num}
let message = when color is {
Green -> "Success."
Blue -> "Warning."
Red -> "Error!"
}
```
Since everything is secretly a function, the last statement in any block is implicitly its return.

View File

@ -1 +1,3 @@
# Bool
Bools are True or False

View File

@ -1 +1,9 @@
# Comments
```
// Line comments begin with a double-slash
/// Doc comments begin with a triple-slash
//// Module comments begin with a quadruple-slash
```

View File

@ -1 +1,46 @@
# Custom types
### Enum Types
Instantiation
```
type Color {
Red
Blue
Green
}
```
Enum types can be thought of as the unit of product types.
Usage
```
fn myFavouriteColor() -> Color {
Red
}
```
### Product Types
```
type MyValue {
Name(String)
Age(Int)
}
```
```
fn eitherNameOrAge(b: Bool) -> MyValue {
if b {
Name("James")
} else {
Age(20)
}
}
```
This example is a bit nonsensical...

View File

@ -1 +1,17 @@
# Variables
Function variables with types
```
fn add(a:Int, b:Int) -> Int {
a + b
}
```
Let bindings
```
fn something(){
let a = 3
let b = 5
a + b
}
```