Skip to content

Instantly share code, notes, and snippets.

@susisu
susisu / brainfuck.ts
Created Mar 9, 2020
Type-level Brainfuck interpreter in TypeScript
View brainfuck.ts
// Type-level Brainfuck interpreter in TypeScript
// Copyright (c) 2020 Susisu (susisu2413@yahoo.co.jp)
type State<P, M, I, O, R, K> = {
program: P,
memory: M,
input: I,
output: O,
return: R,
skip: K,
View loquat-eff.ts
import * as lq from "@loquat/simple";
const key = Symbol("handle");
type PerformFunc = <U>(parser: lq.Parser<U>) => U;
export function handle<T>(func: (perform: PerformFunc) => T): lq.Parser<T> {
return new lq.StrictParser(state => {
let currentState = state;
let currentErr = lq.ParseError.unknown(state.pos);
View test.ts
const ref = <T>(f: (x: T) => T) => {
const r = { val: f };
return () => r;
};
const id = <T>(x: T) => x;
// r: <T>() => { val: (x: T) => T }
const r = ref(id);
// unsafe instantiations of r
const r1 = r<number>();
View poly.ts
const apply = <T, U>(f: (x: T) => U) => (x: T) => f(x);
const foo = <T extends { foo: number }>(x: T) => x.foo;
const foo2 = apply(foo); // : (x: {}) => number;
foo({ foo: 1, bar: 2 }); // OK
foo({}); // error
foo2({ foo: 1, bar: 2 }); // OK
foo2({}); // OK???
View test.hs
-- tf-random 0.5
import System.Random.TF.Gen
-- Utility functions to choose one of splitted generators.
left g = let (g', _) = split g in g'
right g = let (_, g') = split g in g'
-- Initialize a generator (the seed is not relevant).
gen = seedTFGen (0, 0, 0, 0)
-- Let `b` be the tree position bits of a generator and `bi` the index in it. Now `b` and `bi` of
View gist:a1d704f103f03704b5da071c027a4512
λ bin/bench ./gists.json 10000 pegjs
Node.js version: 10.9.0
JSON file: ./gists.json
Loops: 10000
pegjs: 56181.985ms
λ bin/bench ./gists.json 10000 parsimmon
Node.js version: 10.9.0
JSON file: ./gists.json
Loops: 10000
View what.mli
module Iterator: sig
type 'a t
type 'a result =
| Done
| Continue of 'a
val next: 'a t -> 'a result
end
View opt_parser.ts
interface IParser<T> { }
declare class Opt<K extends string, T> {
constructor(key: K, parser: IParser<T>);
}
declare const string: IParser<string>;
declare const number: IParser<number>;
declare class OptParser<P extends {}> {
View chalk.sh
#!/bin/bash
if [ $# -eq 0 ]; then
exit 0;
elif [ $# -eq 1 ]; then
printf "$@"
exit 0
fi
msg=${@: -1:1}
You can’t perform that action at this time.