type StringBool = "true"|"false";
interface AnyNumber { prev?: any, isZero: StringBool };
interface PositiveNumber { prev: any, isZero: "false" };
type IsZero<TNumber extends AnyNumber> = TNumber["isZero"];
type Next<TNumber extends AnyNumber> = { prev: TNumber, isZero: "false" };
type Prev<TNumber extends PositiveNumber> = TNumber["prev"];
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
import java.util.Random; | |
/** | |
* Generates a sequence of pseudo-random numbers such that they never repeat. Can handle sequence sizes up to | |
* length Int.MAX_VALUE. Will throw exceptions if you ask for more than that; maps the entire [0, Integer.MAX_VALUE] | |
* range onto itself but in a random order | |
* <link>http://preshing.com/20121224/how-to-generate-a-sequence-of-unique-random-integers/</link> | |
*/ | |
public class PreshingRandomSequence { | |
public static final int MAX_INT_PRIME = 2147483587; |
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
sealed class Trampoline<A> { | |
class More<A>(val fn: () -> Trampoline<A>): Trampoline<A>() { | |
override fun toString() = "More" | |
} | |
class Done<A>(val a: A): Trampoline<A>() { | |
override fun toString() = "Done($a)" | |
} | |
companion object { | |
fun <A> run(fn: () -> Trampoline<A>): A = run(fn()).let { |
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
license: mit |
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
/// A type equality guarantee is capable of safely casting one value to a | |
/// different type. It can only be created when `S` and `T` are statically known | |
/// to be equal. | |
struct TypeEqualityGuarantee<S, T> { | |
private init() {} | |
/// Safely cast a value to the other type. | |
func cast(_ value: T) -> S { | |
return value as! S | |
} |
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
import kotlin.coroutines.experimental.* | |
import kotlin.coroutines.experimental.intrinsics.* | |
fun main(args: Array<String>) { | |
enumerate { | |
if (flip("A")) { | |
if (flip("B")) 1 else 2 | |
} else { | |
if (flip("C")) 3 else if (flip("D")) 4 else 5 | |
} |
I think I’ve figured out most parts of the cubical type theory papers; I’m going to take a shot to explain it informally in the format of Q&As. I prefer using syntax or terminologies that fit better rather than the more standard ones.
Q: What is cubical type theory?
A: It’s a type theory giving homotopy type theory its computational meaning.
Q: What is homotopy type theory then?
A: It’s traditional type theory (which refers to Martin-Löf type theory in this Q&A) augmented with higher inductive types and the univalence axiom.
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
os.system("kotlinc src/main/kotlin/Launcher.kt -include-runtime -d launcher.jar") | |
process = Popen(['java', '-jar', 'launcher.jar', tmp_file_name], stdout=PIPE) | |
(stdout, stderr) = process.communicate() |
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
infix fun <T,O>List<T>.cartesianProduct(others:List<O>):List<Pair<T,O>> = | |
flatMap{ t:T-> | |
others.map { o-> Pair(t,o) } | |
} | |
inline fun <T, O, R> List<T>.mapCartesianProduct(others: List<O>, transform: (Pair<T, O>) -> R): List<R> = | |
flatMap { t: T -> | |
others.map { o -> transform(Pair(t, o)) } | |
} |