2017-09-06 01:27:09 -07:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
//comments are C-style
|
|
|
|
/* nested comments /* are cool */ */
|
2017-09-06 01:27:09 -07:00
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
}
|
2017-09-06 01:27:09 -07:00
|
|
|
|
2021-10-21 10:45:14 -07:00
|
|
|
|
2021-10-21 01:31:31 -07:00
|
|
|
@annotations use the @ sigil
|
2017-09-06 01:27:09 -07:00
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
// variable expressions
|
2021-10-21 01:31:31 -07:00
|
|
|
//variable declaration works like Rust
|
|
|
|
let a: I32 = 20
|
|
|
|
let mut b: String = 20
|
2017-09-06 01:27:09 -07:00
|
|
|
|
|
|
|
there(); can(); be(); multiple(); statements(); per_line();
|
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
//string interpolation
|
2021-10-21 01:31:31 -07:00
|
|
|
// maybe
|
|
|
|
let yolo = "I have ${a + b} people in my house"
|
2017-09-07 23:39:31 -07:00
|
|
|
|
2021-10-21 01:31:31 -07:00
|
|
|
// let expressions
|
2017-09-07 23:39:31 -07:00
|
|
|
let a = 10, b = 20, c = 30 in a + b + c
|
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
//list literal
|
2021-10-21 01:31:31 -07:00
|
|
|
let q = [1,2,3,4]
|
2017-09-07 23:39:31 -07:00
|
|
|
|
2021-10-21 01:31:31 -07:00
|
|
|
//lambda literal - uses haskell-ish syntax
|
|
|
|
q.map(\(item) { item * 100 })
|
2017-09-07 23:39:31 -07:00
|
|
|
|
2017-09-06 01:27:09 -07:00
|
|
|
fn yolo(a: MyType, b: YourType): ReturnType<Param1, Param2> {
|
|
|
|
if a == 20 {
|
|
|
|
return "early"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-12 23:49:02 -07:00
|
|
|
/* for/while loop topics */
|
2021-10-21 01:31:31 -07:00
|
|
|
//TODO I can probably get away with having one of `for`, `while`
|
2018-05-12 23:49:02 -07:00
|
|
|
|
|
|
|
//infinite loop
|
|
|
|
while {
|
|
|
|
if x() { break }
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//conditional loop
|
|
|
|
while conditionHolds() {
|
|
|
|
...
|
|
|
|
}
|
|
|
|
|
2017-09-06 01:27:09 -07:00
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
//iteration over a variable
|
2017-09-06 01:27:09 -07:00
|
|
|
for i <- [1..1000] {
|
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
} //return type is return type of block
|
2017-09-06 01:27:09 -07:00
|
|
|
|
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
//monadic decomposition
|
2017-09-17 06:22:19 -07:00
|
|
|
for {
|
|
|
|
a <- maybeInt();
|
2021-10-21 01:31:31 -07:00
|
|
|
s <- foo()
|
2017-09-17 06:22:19 -07:00
|
|
|
} return {
|
2017-09-06 01:27:09 -07:00
|
|
|
a + s
|
2018-03-17 23:38:37 -07:00
|
|
|
} //return type is Monad<return type of block>
|
2017-09-06 01:27:09 -07:00
|
|
|
|
2018-05-12 23:49:02 -07:00
|
|
|
/* end of for loops */
|
|
|
|
|
|
|
|
|
2017-09-06 01:27:09 -07:00
|
|
|
|
2018-05-12 23:49:02 -07:00
|
|
|
/* conditionals/pattern matching */
|
2017-09-06 01:27:09 -07:00
|
|
|
|
2021-10-21 01:31:31 -07:00
|
|
|
// `is` functions as an operator asking "does this pattern match"
|
2017-09-07 23:39:31 -07:00
|
|
|
|
2018-05-12 23:49:02 -07:00
|
|
|
x is Some(t) // type bool
|
|
|
|
|
|
|
|
if x {
|
|
|
|
is Some(t) => {
|
|
|
|
},
|
|
|
|
is None => {
|
2017-09-07 23:39:31 -07:00
|
|
|
|
|
|
|
}
|
2018-05-12 23:49:02 -07:00
|
|
|
}
|
|
|
|
|
2017-09-07 23:39:31 -07:00
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
//syntax is, I guess, for <expr> <brace-block>, where <expr> is a bool, or a <arrow-expr>
|
2017-09-07 23:39:31 -07:00
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
// type level alises
|
2021-10-21 01:31:31 -07:00
|
|
|
type alias <name> = <other type> #maybe thsi should be 'alias'?
|
2017-09-13 23:04:26 -07:00
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
/*
|
|
|
|
what if type A = B meant that you could had to create A's with A(B), but when you used A's the interface was exactly like B's?
|
|
|
|
maybe introduce a 'newtype' keyword for this
|
|
|
|
*/
|
2017-09-14 00:11:52 -07:00
|
|
|
|
2018-03-17 23:38:37 -07:00
|
|
|
//declaring types of all stripes
|
2021-10-21 01:31:31 -07:00
|
|
|
type MyData = { a: i32, b: String } // shorthand special-case for `type MyData = MyData { a: i32, b: String }`
|
2017-09-07 22:29:23 -07:00
|
|
|
type MyType = MyType
|
|
|
|
type Option<a> = None | Some(a)
|
|
|
|
type Signal = Absence | SimplePresence(i32) | ComplexPresence {a: i32, b: MyCustomData}
|
|
|
|
|
2021-10-21 01:31:31 -07:00
|
|
|
//traits TODO I probably want to rename this
|
2017-09-07 22:29:23 -07:00
|
|
|
|
|
|
|
trait Bashable { }
|
|
|
|
trait Luggable {
|
|
|
|
fn lug(self, a: Option<Self>)
|
|
|
|
}
|
|
|
|
|
2017-09-06 01:27:09 -07:00
|
|
|
}
|
2018-03-04 02:11:22 -08:00
|
|
|
|
2021-10-21 01:31:31 -07:00
|
|
|
// lambdas - maybe I want to use ruby-style (not rust style) syntax
|
|
|
|
// e.g.
|
|
|
|
// Also TODO Nix uses `X: Y: Z` for in its value-level syntax, why can't I?
|
|
|
|
let a: X -> Y -> Z = {|x,y| }
|