schala/source_files/schala/syntax_playground.schala
2021-11-11 23:42:22 -08:00

116 lines
2.2 KiB
Plaintext

fn main() {
//comments are C-style
/* nested comments /* are cool */ */
}
@annotations use the @ sigil
// variable expressions
//variable declaration works like Rust
let a: I32 = 20
let mut b: String = 20
there(); can(); be(); multiple(); statements(); per_line();
//string interpolation
// maybe
let yolo = "I have ${a + b} people in my house"
// let expressions
let a = 10, b = 20, c = 30 in a + b + c
//list literal
let q = [1,2,3,4]
//lambda literal - uses haskell-ish syntax
q.map(\(item) { item * 100 })
fn yolo(a: MyType, b: YourType): ReturnType<Param1, Param2> {
if a == 20 {
return "early"
}
}
/* for/while loop topics */
//TODO I can probably get away with having one of `for`, `while`
//infinite loop
while {
if x() { break }
...
}
//conditional loop
while conditionHolds() {
...
}
//iteration over a variable
for i <- [1..1000] {
} //return type is return type of block
//monadic decomposition
for {
a <- maybeInt();
s <- foo()
} return {
a + s
} //return type is Monad<return type of block>
/* end of for loops */
/* conditionals/pattern matching */
// `is` functions as an operator asking "does this pattern match"
x is Some(t) // type bool
if x {
is Some(t) => {
}
is None => {
}
}
//syntax is, I guess, for <expr> <brace-block>, where <expr> is a bool, or a <arrow-expr>
// type level alises
type alias <name> = <other type> #maybe thsi should be 'alias'?
/*
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
*/
//declaring types of all stripes
type MyData = { a: i32, b: String } // shorthand special-case for `type MyData = MyData { a: i32, b: String }`
type MyType = MyType
type Option<a> = None | Some(a)
type Signal = Absence | SimplePresence(i32) | ComplexPresence {a: i32, b: MyCustomData}
//traits TODO I probably want to rename this
trait Bashable { }
trait Luggable {
fn lug(self, a: Option<Self>)
}
}
// 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| }