Skip to content

Instantly share code, notes, and snippets.

@kmizu
Last active October 1, 2018 16:03
Show Gist options
  • Save kmizu/dbaa51370262aaad84c0553184677d29 to your computer and use it in GitHub Desktop.
Save kmizu/dbaa51370262aaad84c0553184677d29 to your computer and use it in GitHub Desktop.
Facebookの新言語Skipの構文を雑に見てみた(1) ref: https://qiita.com/kmizu/items/51c01dd6a13592b4e758
fun add(x: Int, y: Int): Int {
x + y
}
fun add(x: Int, y: Int): Int {
z = y;
!z = 1;
x + z
}
fun identity<T>(x: T): T { x }
class MyReference<T>(T)
fun sum<T: IntConvertible>(v: Vector<T>): ...
trait Showable {
fun toString(): String;
}
class Math {
static fun plus1(x: Int): Int {
x + 1
}
}
fun testMath(): Int {
Math::plus1(0)
}
trait Hashable {
fun hash(): Int;
}
extension class String uses Hashable {
fun hash(): Int {
...
}
}
base class MyValue {value: this::TV} {
type TV;
deferred static fun make(value: TV): this {
static { value }
}
}
class Child extends MyValue {
type TV = Int;
// inherited
// static fun make(value: Int): this
}
value class Pair(x: Int, y: Int)
my_pair = (1, 2);
my_pair = Tuple2(1, 2);
fun add(x: Int, y:Int): Int {
y: Int = 0; // yはInt
!z = 1;
x + z
}
fun notVeryUseful(): void {
x = void;
x
}
fun getAgeWhile(name: String, people: Sequence<Person>): Int {
iter = people.values();
current = iter.next();
while (current.isSome()) {
person = current.fromSome();
if (person.name == name) {
break person.age
}
!current = iter.next();
} else -1 // Return -1 if the person is not found.
}
fun sumVector(v: Vector<Int>): Int {
sum = 0;
v.each(x -> !sum = sum + x);
sum
}
class Point(x: Int, y: Int) {
fun add1X(): Point {
Point(this.x + 1, this.y)
}
}
class Person {name: String, age: Int}
fun main(): void {
p = Person {name => "Kota Mizushima", age => 34};
print_raw(`p.age = ${p.age}`)
}
base class Parent<T> {
children = A() | B(Int) | C(Int, Bool)
}
base class Parent<T>
class A<T>() extends Parent<T>
class B<T>(Int) extends Parent<T>
class C<T>(Int, Bool) extends Parent<T>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment