「そもそも概念が分からない」という方に向けた説明です.
簡略化のため大幅に説明を省略しています. ご容赦ください.
誤りは御指摘いただければ幸いです.
「ファンクタ」, 「アプリカティブ」, 「モナド」 などは Haskell に限定された概念・用語ではありませんが,
# >> を * | |
# >>= を bind | |
# return を self.new | |
# mplus を + | |
# mzero を self.zero | |
# | |
# に見立てて Maybe モナド書いてみた | |
# bind に渡す block で Maybe と書きたくないので第二引数に型情報を付加してみた。 | |
class Monad | |
def *(m) |
class FlorContinue | |
constructor: (key)-> | |
@key = key | |
class FlorEnd | |
class Flor | |
@_id = 1 | |
@generateId = ()-> |
use std::rc::Rc; | |
trait HKT<U> { | |
type C; // Current type | |
type T; // Type with C swapped with U | |
} | |
macro_rules! derive_hkt { | |
($t:ident) => { | |
impl<T, U> HKT<U> for $t<T> { |
use std::rc::Rc; | |
pub trait HKT<U> { | |
type C; // Current type | |
type T; // Type with C swapped with U | |
} | |
macro_rules! derive_hkt { | |
($t:ident) => { | |
impl<T, U> HKT<U> for $t<T> { |
// http://hackage.haskell.org/package/base-4.9.1.0/docs/src/GHC.Base.html | |
// (f, g, h) => x => h(f(g(x))) | |
const compose = | |
(...fns) => | |
initial => | |
fns.reduceRight( | |
(result, fn) => fn(result), | |
initial | |
) |
Section "InputClass" | |
Identifier "Coordinate Transformation Matrix" | |
MatchIsTouchscreen "on" | |
MatchDevicePath "/dev/input/event*" | |
MatchDriver "libinput" | |
Option "CalibrationMatrix" "0 1 0 -1 0 1 0 0 1" | |
EndSection | |
パターンとはその言語が抽象化できなかった敗北の歴史である。 しかしどんなに優れた言語であってもあらゆる繰り返しに勝てるわけではない。 人は必ずメタ繰り返しを欲するからだ。 そしてそれはRustも例外ではない。
ここでは、OOPでも知られているパターンよりも、Rustに特有のパターンを思いつく限りまとめてみた。名前は適当。