Skip to content

Instantly share code, notes, and snippets.

View t2ru's full-sized avatar

Tetsuya Takatsuru t2ru

  • Chiba, Japan
View GitHub Profile
(defprotocol Monad
(return [m v])
(bind [m mv f]))
(defprotocol MonadPlus
(mzero [m])
(mplus [m mv mw]))
;; identity monad
@t2ru
t2ru / monad.rst
Created July 5, 2014 11:21
モナドとかのメモ

Functor

  • fmap : (a -> b) -> m a -> m b
    • f : a -> b
    • mv : m a
    • fmap f mv : m b

Applicative Functor

@t2ru
t2ru / error_monad.clj
Created July 5, 2014 11:10
clojure.algo.monads用のerror monadとそのテスト
(ns testmonad.amonad-test
(:use [clojure.test]
[clojure.algo.monads]))
(defprotocol Either
(either-call [obj on-left on-right]))
(defrecord Left [v]
Either (either-call [obj on-left on-right] (on-left v)))
(defrecord Right [v]
Either (either-call [obj on-left on-right] (on-right v)))
@t2ru
t2ru / monad_sample1.clj
Created July 5, 2014 11:08
モナドのサンプル1
(ns testmonad.core)
;;; Typeclass Protocols
(defprotocol Functor
(fmap [mv f] "f : a -> b, mv : m a, fmap f mv : m b"))
(defprotocol Applicative
(ap [mf mv] "mf : m (a -> b), mv : m a, ap mf mv : m b"))
@t2ru
t2ru / conf.py
Created June 12, 2014 19:18
Sphinx(latex→PDF)で図がはみ出さないようにする方法 ref: http://qiita.com/t2ru/items/a19560dc707bf77c432b
# 末尾に追加
latex_elements['preamble'] = r'''
\usepackage[export]{adjustbox}
\usepackage{letltxmacro}
\LetLtxMacro{\origincludegraphics}{\includegraphics}
\renewcommand*\includegraphics[2][max width=\textwidth,max height=\textheight,keepaspectratio]{%
\begin{figure}[htbp]
\origincludegraphics[#1]{#2}
\end{figure}
---
- hosts:
- servers
vars:
ansible_ssh_user: root
tasks:
- name: make sure local keys directory exists
local_action: file path=./keys state=directory
- name: check key pair exists
local_action: command test -f keys/id_rsa
@t2ru
t2ru / core.clj
Created October 12, 2013 06:32
ClojureでSEND+MORE=MONEYを解いた ref: http://qiita.com/t2ru/items/b47da0ebcf04ec551312
(ns smm.core
(:refer-clojure :exclude [==])
(:use [clojure.core.logic])
(:require [clojure.core.logic.fd :as fd]))
;;; S E N D
;;; + M O R E
;;; ---------
;;; M O N E Y