Update schala example code
This commit is contained in:
parent
5ab7c2d254
commit
638afd47cc
@ -1,30 +1,30 @@
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
# comments are scripting-style
|
//comments are C-style
|
||||||
#{ but can also be
|
/* nested comments /* are cool */ */
|
||||||
|
|
||||||
}# blocks
|
}
|
||||||
|
|
||||||
@annotations are with @-
|
@annotations are with @-
|
||||||
|
|
||||||
# variable expressions
|
// variable expressions
|
||||||
var a: I32 = 20
|
var a: I32 = 20
|
||||||
const b: String = 20
|
const b: String = 20
|
||||||
|
|
||||||
there(); can(); be(); multiple(); statements(); per_line();
|
there(); can(); be(); multiple(); statements(); per_line();
|
||||||
|
|
||||||
#string interpolation
|
//string interpolation
|
||||||
const yolo = "I have ${a + b} people in my house"
|
const yolo = "I have ${a + b} people in my house"
|
||||||
|
|
||||||
# let expressions ??? not sure if I want this
|
// let expressions ??? not sure if I want this
|
||||||
let a = 10, b = 20, c = 30 in a + b + c
|
let a = 10, b = 20, c = 30 in a + b + c
|
||||||
|
|
||||||
#list literal
|
//list literal
|
||||||
const q = [1,2,3,4]
|
const q = [1,2,3,4]
|
||||||
|
|
||||||
#lambda literal ?? maybe? not sure how this should work
|
//lambda literal
|
||||||
q.map(|item| { item * 100 })
|
q.map({|item| item * 100 })
|
||||||
|
|
||||||
fn yolo(a: MyType, b: YourType): ReturnType<Param1, Param2> {
|
fn yolo(a: MyType, b: YourType): ReturnType<Param1, Param2> {
|
||||||
if a == 20 {
|
if a == 20 {
|
||||||
@ -36,35 +36,35 @@ fn main() {
|
|||||||
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
# infinite loop
|
//infinite loop
|
||||||
}
|
}
|
||||||
|
|
||||||
#iteration over a variable
|
//iteration over a variable
|
||||||
for i <- [1..1000] {
|
for i <- [1..1000] {
|
||||||
|
|
||||||
} #return type is return type of block
|
} //return type is return type of block
|
||||||
|
|
||||||
#while loop
|
//while loop
|
||||||
for a != 3 || fuckTard() {
|
for a != 3 || fuckTard() {
|
||||||
break
|
break
|
||||||
} #return type is return type of block
|
} //return type is return type of block
|
||||||
|
|
||||||
#monadic decomposition
|
//monadic decomposition
|
||||||
for {
|
for {
|
||||||
a <- maybeInt();
|
a <- maybeInt();
|
||||||
s <- foo()
|
s <- foo()
|
||||||
} return {
|
} return {
|
||||||
a + s
|
a + s
|
||||||
} #return type is Monad<return type of block>
|
} //return type is Monad<return type of block>
|
||||||
|
|
||||||
# let statements too!!
|
// let statements too!!
|
||||||
for (a = 20
|
for (a = 20
|
||||||
b = fuck) {
|
b = fuck) {
|
||||||
a + b
|
a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# pattern-matching
|
// pattern-matching
|
||||||
match <expr> {
|
match <expr> {
|
||||||
Some(a) => {
|
Some(a) => {
|
||||||
|
|
||||||
@ -74,21 +74,23 @@ fn main() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#syntax is, I guess, for <expr> <brace-block>, where <expr> is a bool, or a <arrow-expr>
|
//syntax is, I guess, for <expr> <brace-block>, where <expr> is a bool, or a <arrow-expr>
|
||||||
|
|
||||||
# type level alises
|
// type level alises
|
||||||
typealias <name> = <other type> #maybe thsi should be 'alias'?
|
typealias <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
|
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
|
//declaring types of all stripes
|
||||||
type MyData = { a: i32, b: String }
|
type MyData = { a: i32, b: String }
|
||||||
type MyType = MyType
|
type MyType = MyType
|
||||||
type Option<a> = None | Some(a)
|
type Option<a> = None | Some(a)
|
||||||
type Signal = Absence | SimplePresence(i32) | ComplexPresence {a: i32, b: MyCustomData}
|
type Signal = Absence | SimplePresence(i32) | ComplexPresence {a: i32, b: MyCustomData}
|
||||||
|
|
||||||
#traits
|
//traits
|
||||||
|
|
||||||
trait Bashable { }
|
trait Bashable { }
|
||||||
trait Luggable {
|
trait Luggable {
|
||||||
@ -98,8 +100,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# lambdas
|
// lambdas
|
||||||
#
|
// ruby-style not rust-style
|
||||||
|x,y| { }() #is probably fine
|
const a: X -> Y -> Z = {|x,y| }
|
||||||
const a = |x: Type, y|: RetType { <statementblock> }
|
|
||||||
const a: X -> Y -> Z = |x,y| { }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user