Skip to content

Instantly share code, notes, and snippets.

@cohama
cohama / gist:3883219
Created October 13, 2012 04:27
TypeScript のオブジェクト志向練習
interface IGreeter {
greet(): string;
}
class NameGreeter implements IGreeter {
constructor(public name: string) {}
public greet(): string {return this.name}
}
class CountGreeter implements IGreeter {
private count: number = 0;
public greet(): string {return this.count++ + "th";}
@cohama
cohama / git diff copy
Created October 16, 2012 01:01
git で変更のあったファイルだけを抽出してコピーする。
git diff --stat HEAD^ | awk '/¥|/ {print ¥1}' | xarg cp --parents -t ./HOGEDIR
@cohama
cohama / expr.ml
Created April 14, 2013 09:32
ocaml-expr
type expression =
| Const of float
| Var of string
| Sum of expression * expression
| Diff of expression * expression
| Prod of expression * expression
| Quot of expression * expression;;
exception Unbound_variable of string;;
@cohama
cohama / prio_queue.ml
Created April 15, 2013 14:04
structure
module type PRIOQUEUE =
sig
type priority = int
type 'a queue
val empty : 'a queue
val insert : 'a queue -> int -> 'a -> 'a queue
val extract : 'a queue -> int * 'a * 'a queue
exception Queue_is_empty
end;;
@cohama
cohama / functor.ml
Created April 15, 2013 14:47
functor
type comparison = Less | Equal | Greater;;
module type ORDERED_TYPE =
sig
type t
val compare: t -> t -> comparison
end;;
module Set =
functor (Elt: ORDERED_TYPE) ->
@cohama
cohama / bigstep_eval.ml
Last active December 17, 2015 12:09
TaPL 演習 3.5.17
type info = string
type term =
| TmTrue
| TmFalse
| TmIf of term * term * term
| TmZero
| TmSucc of term
| TmPred of term
| TmIsZero of term
The following actions will be performed:
- install spotinstall.1.1.0
1 to install | 0 to reinstall | 0 to upgrade | 0 to downgrade | 0 to remove
=-=-= Installing spotinstall.1.1.0 =-=-=
The archive for spotinstall.1.1.0 is in the local cache.
Extracting /home/cohama/.opam/archives/spotinstall.1.1.0+opam.tar.gz.
Building spotinstall.1.1.0:
ocaml setup.ml -configure --prefix /home/cohama/.opam/4.00.1+annot
ocaml setup.ml -build
if has('vim_starting')
set runtimepath+=~/tmp/bundle/neobundle.vim/
endif
call neobundle#rc(expand('~/tmp/bundle/'))
NeoBundleLazy 'Shougo/vimfiler', {
\ 'autoload' : {
\ 'commands' : ['VimFiler'],
\ }}
let s:V = vital#of('vital')
let s:S = s:V.import('Data.String')
let start = reltime()
let test1 = s:S.substitute_last(repeat('vim is vital', 1000), 'i', 'ooo')
let elapsed = reltimestr(reltime(start))
echo "substitute last" elapsed
let start = reltime()
let test2 = substitute(repeat('vim is vital', 1000), 'i', 'ooo', '')
let elapsed = reltimestr(reltime(start))
@cohama
cohama / onestep_eval.ml
Last active November 27, 2021 12:14
TaPL 7 章 型なしラムダ計算の1ステップ評価の OCaml による実装
(* Utilities *)
let (|>) x f = f x
let (|-) f g = fun x -> g (f x)
let getOrElse defVal = function
| Some(v) -> v
| None -> defVal
(* Term Definition *)
type term =
| TmVar of int * int (* 変数 : deBruijn_index * term_length *)