Skip to content

Instantly share code, notes, and snippets.

@cohama
cohama / test.md
Last active August 2, 2021 03:34

りすと

  • リスト
  • になる

これは

  • リストに
  • なる
@cohama
cohama / cps2.rs
Last active August 7, 2017 22:18
fn main() {
repeat_cps(10, "hello", Box::new(|r| {
println!("{:?}", r)
}))
}
fn repeat_cps<'a, A, B>(n: i32, x: A, k: Box<Fn(A) -> B + 'a>) -> B
{
if n == 0 {
k(x)
fn main() {
println!("{:?}", take_while(&[1, 2, 3, 4, 5], |&x| x < 3));
}
fn take_while<T, F>(xs: &[T], f: F) -> &[T]
where F: Fn(&T) -> bool
{
let mut i = 0;
while f(&xs[i]) {
i += 1;
/* eslint no-console: "off", no-unused-vars: "off" */
var xs = [
{id: 'A', pid: '', name: 'aaa'},
{id: 'B', pid: '', name: 'bbb'},
{id: 'C', pid: '', name: 'ccc'},
{id: 'A-a', pid: 'A', name: 'aaa-aaa'},
{id: 'A-b', pid: 'A', name: 'aaa-bbb'},
{id: 'B-a', pid: 'B', name: 'bbb-aaa'},
{id: 'B-b', pid: 'B', name: 'bbb-bbb'},
{id: 'C-a', pid: 'C', name: 'ccc-aaa'},
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
import Data.Ratio
class (Num a) => Dividable a where
divide :: a -> a -> a
instance {-# INCOHERENT #-} (Integral a) => Dividable a where
divide = div
instance Dividable Double where
fn :: [String] -> Int -> String
fn ~(h:t) n = if n == 0
then "oops."
else h ++ ":" ++ show t
main :: IO ()
main = putStrLn $ fn [] 0
"use strict"
const ZERO = f => x => x
const ONE = f => x => f(x)
const TWO = f => x => f(f(x))
const THREE = f => x => f(f(f(x)))
const FOUR = f => x => f(f(f(f(x))))
const FIVE = f => x => f(f(f(f(f(x)))))
const SUCC = n => f => x => n(f)(f(x))

Twitter クライアントを作る

準備

git clone git://github.com/cohama/twittermonad
cd twittermonad
cabal sandbox init
cabal install --only-dependencies
cabal configure
@cohama
cohama / t.rb
Created November 14, 2014 15:28
describe "hoge" do
let (:hoge) {1}
it "first" do
expect(1).to eq hoge
end
describe "child" do
@cohama
cohama / t.js
Last active August 29, 2015 14:09
var assert = require('assert');
describe('hoge', function() {
beforeEach(function() {
this.foo = 1;
this.bar = 5;
THIS = this;
});
it('first', function() {