Entries from 2014-09-01 to 1 month

【Ruby】emacs上でirbを走らせる

emacsくわしくありません。全然理解していません。備忘録的に書きます。 ★emacs上でirbを動かせたらいいな 以下、やったことです。 ■~/.emacs.d/init.elに以下を追加 (require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.…

【Haskell】すごいHaskellたのしく学ぼう 第14章演習問題

import Data.List import Data.Ratio newtype Prob a = Prob {getProb :: [(a, Rational)]} deriving Show flatten :: Prob (Prob a) -> Prob a flatten (Prob xs) = Prob $ concat $ map multAll xs where multAll (Prob innerxs, p) = map (\(x, r) -> (x,…

【C++】vectorの連結【滅びろ】

C++ってめんどくしゃい。 vectorの連結やってみた。 #include <iostream> #include <vector> using namespace std; int main(int argc, char* argv[]){ vector<int> v1; vector<int> v2; v1.push_back(1); v1.push_back(2); v1.push_back(3); v2.push_back(4); v2.push_back(5); v2.push_</int></int></vector></iostream>…

モナド則は<=<という演算子で簡単になる

演算子を以下のように定義する。 (<=<) :: (Monad m) => (b -> m c) -> (a -> m b) -> (a -> m c) f <=< g = (\x -> g x >>= f) するとモナド則は以下のようになる。 return <=< f = f f <=< return = f (f <=< g) <=< h = f <=< (g <=< h)

【Haskell】モノイドで畳み込む

import Data.Monoid import qualified Data.Foldable as F data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show) instance F.Foldable Tree where foldMap f EmptyTree = mempty foldMap f (Node x l r) = F.foldMap f l `mappend` f x `map…