Last active
October 1, 2018 16:03
-
-
Save kmizu/dbaa51370262aaad84c0553184677d29 to your computer and use it in GitHub Desktop.
Facebookの新言語Skipの構文を雑に見てみた(1) ref: https://qiita.com/kmizu/items/51c01dd6a13592b4e758
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun add(x: Int, y: Int): Int { | |
x + y | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun add(x: Int, y: Int): Int { | |
z = y; | |
!z = 1; | |
x + z | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun identity<T>(x: T): T { x } | |
class MyReference<T>(T) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun sum<T: IntConvertible>(v: Vector<T>): ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Showable { | |
fun toString(): String; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Math { | |
static fun plus1(x: Int): Int { | |
x + 1 | |
} | |
} | |
fun testMath(): Int { | |
Math::plus1(0) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Hashable { | |
fun hash(): Int; | |
} | |
extension class String uses Hashable { | |
fun hash(): Int { | |
... | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
value class Pair(x: Int, y: Int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_pair = (1, 2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_pair = Tuple2(1, 2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun add(x: Int, y:Int): Int { | |
y: Int = 0; // yはInt | |
!z = 1; | |
x + z | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun notVeryUseful(): void { | |
x = void; | |
x | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun sumVector(v: Vector<Int>): Int { | |
sum = 0; | |
v.each(x -> !sum = sum + x); | |
sum | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Point(x: Int, y: Int) { | |
fun add1X(): Point { | |
Point(this.x + 1, this.y) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person {name: String, age: Int} | |
fun main(): void { | |
p = Person {name => "Kota Mizushima", age => 34}; | |
print_raw(`p.age = ${p.age}`) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base class Parent<T> { | |
children = A() | B(Int) | C(Int, Bool) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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