Skip to content

Instantly share code, notes, and snippets.

View pasberth's full-sized avatar

pasberth pasberth

View GitHub Profile
hello
@pasberth
pasberth / printf.hs
Created February 19, 2014 03:24
可変長引数つきの printf
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
format :: String -> String -> String
format [] _ = []
format ('%':'%':s) x = '%' : '%' : format s x
format ('%':'s':s) x = escape x ++ s
format (x:xs) y = x : format xs y
escape :: String -> String
@pasberth
pasberth / README.md
Created February 16, 2014 15:09
sweet.js でのアレ
sjs --module ./mod.js --output fn.built.js fn.js
sjs --module ./mod.js --output fn2.built.js fn2.js
sjs --module ./mod.js --output fn3.built.js fn3.js
$ ghc -O2 a.hs
$ time ./a
./a  1.39s user 1.70s system 69% cpu 4.479 total
$ ghc -O2 b.hs
$ time ./b
./b  1.52s user 1.73s system 73% cpu 4.448 total
$ ghc a.hs
$ time ./a
./a  1.51s user 1.67s system 77% cpu 4.082 total
$ ghc b.hs
$ time ./b
./b  1.58s user 1.68s system 78% cpu 4.126 total
@pasberth
pasberth / syllogism
Created January 25, 2014 08:13
三段論法
Theorem syllogism : forall (A B C : Prop), (B -> C) -> (A -> B) -> A -> C.
Proof.
intros A B C H H0 H1.
apply H.
apply H0.
apply H1.
Qed.
@pasberth
pasberth / default.hs
Created January 25, 2014 07:56
default宣言
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.ByteString
default (ByteString)
s = "hello world"
-- :: ByteString
-- デフォルトが ByteSTring になる
@pasberth
pasberth / print_all.cpp
Created January 12, 2014 01:34
すべての要素を出力する
#include <string>
#include <vector>
#include <list>
#include <iostream>
template<class Iterator>
void print_all(Iterator first, Iterator last)
{
while (first != last)
{
@pasberth
pasberth / vtable.cpp
Created January 9, 2014 14:35
進捗です
#include <iostream>
typedef void (*f_t)();
class Base {
public:
virtual void f();
};
struct Derivied : public Base {
@pasberth
pasberth / while.hs
Last active January 2, 2016 11:59
whileを使ったループ
import Data.IORef
doWhile :: Monad m => m Bool -> m a -> m a
doWhile test body = do
x <- body
testResult <- test
if testResult
then doWhile test body
else return x