Skip to content

Instantly share code, notes, and snippets.

View pasberth's full-sized avatar

pasberth pasberth

View GitHub Profile
@pasberth
pasberth / IOMonad.py
Created August 31, 2013 11:47
IO モナドの概念的な
# coding: utf8
from sys import stdout, stdin
class IO(object):
pass
class Return(IO):
def __init__(self, x):
@pasberth
pasberth / README.md
Last active December 22, 2015 01:38
Idris で hello world

(Idris version 0.9.7) でテストされています

$ idris a.idr --target javascript -o hello.js
$ node hello.js
hello world
@pasberth
pasberth / template-fizzbuzz.cpp
Created August 28, 2013 06:06
template で fizzbuzz
#include <string>
#include <iostream>
template <unsigned long N>
struct fizzbuzz
{
static void run()
{
fizzbuzz<N-1>::run();
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
-- 基本となるオブジェクト
data Obj = Obj {
_pos :: Int
} deriving (Show)
-- Obj型のオブジェクトをもつ抽象的なクラスHasObjを作る
makeClassy ''Obj
@pasberth
pasberth / hyphen-option.rb
Created August 19, 2013 09:52
こんなのどうだろう
class Symbol
def -@
{ self => true }
end
end
require "json"
p JSON.parse '{"x":42}' # => {"x"=>42}
@pasberth
pasberth / self.cpp
Created August 19, 2013 07:49
self したいアレ
struct T {
T& self;
public:
T() : self(*this) {};
};
@pasberth
pasberth / let.rb
Created August 18, 2013 11:53
let するやつ
module Let
def let(*args, &block)
raise ArgumentError, "%s: expected an even number, got %d." % [__method__, args.size] unless args.size.even?
args.each_with_index.each_slice(2) do |(x,i),(y,j)|
raise ArgumentError, "%s: expected an symbol, got %s (pos %d)" % [__method__, x.inspect, i] if not x.respond_to? :to_sym
end
a = self.clone
@pasberth
pasberth / CLw.txt
Last active December 20, 2015 23:29
現代数理論理学序説読んでる
 組み合わせ論理の体系 CLw を定義します。
基本記号, 表現, 出現
================================================================================
CLw の基本記号は加算個の変数 `u0', `u1', `u2', ... と
`K', `S' を含む定数記号と カッコ `(', `)' です。
 記号(*)の有限列や記号をある形に配置したもののことを表現といいます。
その現れる場所も含めて記号を指定するとき、出現という言葉を使います。
@pasberth
pasberth / module_syntax.rb
Created August 11, 2013 20:51
たのしいるびー
def defmodule(name, &block)
mod = Module.new
mod.module_eval(&block)
const_set(name, mod)
end
def defclass(name, &block)
klass = Class.new
klass.class_eval(&block)
const_set(name, klass)
@pasberth
pasberth / parser.sh
Last active December 20, 2015 16:58
Parsef ( https://github.com/pasberth/parsef ) でパースする example
cd "`dirname $0`"
export PATH="../bin:$PATH"
export FORMULAV="α β γ"
list-expr () {
foldl -@'|' formula "α
::
|
β" '|' α '|' β | formula "α