Skip to content

Instantly share code, notes, and snippets.

import System.Random (RandomGen, getStdGen, randoms)
import Control.Concurrent (threadDelay)
import System.Process (callCommand)
import Data.List.Split (chunksOf)
import Data.Maybe (fromMaybe)
type Cell = Bool
type CellTable = [[Cell]]
type Score = Int
type Pos = (Int, Int)

y x = x (y x)の型推論

  1. y :: bとおく。
  2. x :: cとおく。
  3. y x :: dとおく。
  4. (1.)(2.)(3.)よりbc -> dは等しい。
  5. (4.)よりy :: c -> dである。
  6. x (y x) :: aとおく。
  7. (2.)(3.)(6.)よりcd -> aは等しい。
  8. (2.)(7.)よりx :: d -> aである。
var canvas;
var ctx;
var x;
var y;
var isRightPressed;
var isLeftPressed;
var isUpPressed;
var isDownPressed;
window.addEventListener('load', function() {
function quicksort([x, ...xs]: number[]): number[] {
return typeof x === 'undefined' ? [] : (() => {
const smallerSorted = quicksort(xs.filter(a => a <= x));
const biggerSorted = quicksort(xs.filter(a => a > x));
return [...smallerSorted, x, ...biggerSorted];
})();
}
const { value, stories } = new Writer(3, ['3'])
.write(x => [x * 5, '* 5'])
.write(x => [x + 3, '+ 3']);
print(value).next(() => print(stories.join(' '))).run();
// Output:
// 18
// 3 * 5 + 3
Task.delay(1000).next(() => print('Yeah'));
// Task
const logTask = Task.sync<string, void>(text => console.log(text));
const taskA = Task.delay(1000).map(() => 1 + 2 + 3).map(String);
const taskB = Task.resolve('Hello');
Task.all([taskA, taskB]).map(xs => xs.join(', ')).next(logTask).run();
Task.race([taskA, taskB]).next(logTask).run();
// Promise
const logPromise = (text: string) => console.log(text);
const promiseA = new Promise<void>(resolve => setTimeout(resolve, 1000)).then(() => 1 + 2 + 3).then(String);
var p = console.log.bind(console);
var q = require('readline-sync').question;
var r = () => Math.floor(Math.random()*15)+1
var i = 1;
for(;;) {
var x = r();
p(`(${i}) ${Math.pow(x, 2)}`);
var a = parseInt(q('Input the answer: '));
var c = a === x;
p(c ? 'Good!' : `Bad: The correct answer is ${x}`);
var p = console.log.bind(console);
var q = require('readline-sync').question;
var gcd = (a, b) => !b ? a : gcd(b, a % b);
var r = () => Math.floor(Math.random()*9)+1
var i = 1;
for(;;) {
var x = r();
var y = r();
var df = x % y === 0;
if(df) continue;
interface Functor<A> {
map<B>(f: (a: A) => B): Functor<B>;
}
interface Monad<A> extends Functor<A> {
map<B>(f: (a: A) => B): Monad<B>;
bind<B>(f: (a: A) => Monad<B>): Monad<B>;
}
interface Eq<A> {