(direct sum): • ͨͩ͠ 0, 1 0 ≠ 1 Ͱ͋ΔΑ͏ͳλά • ΑΓҰൠʹ A ⇥ B = {(a, b) | a 2 A ^ b 2 B} A + B = {(0, a) | a 2 A} [ {(1, b) | b 2 B} Y i20..n Xi = {( x0, · · · , xn) | x0 2 X0 ^ · · · ^ xn 2 Xn } a i20..n Xi = [ i20..n {( i, xi) | xi 2 Xi }
class Succ(n: Nat) extends Nat sealed trait List[+A] case object Nil extends List[Nothing] case class Cons[A](hd: A, tl: List[A]) extends List[A] sealed trait BinTree[+A] case object Nil extends BinTree[Nothing] case class Node( v: A, l: BinTree[A], r: BinTree[A]) extends BinTree[A]
: nat -> nat. Inductive list (A : Type) := | nil : list A | cons : A -> list A -> list A. Inductive bin_tree (A : Type) := | empty : bin_tree A | node : A -> bin_tree A -> bin_tree A -> bin_tree A.
࢝ରʹͳΔͱ͍͏͜ͱɺҙͷ F- (X, x) ʹରͯͪ͠ΐ͏ͲҰͭͷ४ಉܕ ͕ଘࡏ͢Δͱ͍͏͜ͱ • ίϯετϥΫλ α Λɺα ͷܕʹݱΕΔ T Λ X ʹม͑ͨؔ x ʹஔ͖͑ͯɺࣗ ࣗͷܕ͕ݱΕ͍ͯΔͱ͜Ζ࠶ؼ͢ΔΑ͏ʹ͢ΔͱɺҙͷF- (X, x) ʹ ରͯͪ͠ΐ͏ͲҰͭͷ४ಉܕΛ࡞Δ͜ͱ͕Ͱ͖Δ • ྫ: Either a b ܕԼͷΑ͏ͳఆٛͰ४ಉܕΛ࡞ΕΔ data Either a b = Left a | Right b either_cata : (a -> x) -> (b -> x) -> Either a b -> x either_cata lf rf (Left a) = lf a either_cata lf rf (Right b) = rf b
-- F(X) = 1 + X ͱͯ͠ɺ -- Լͷ nat_cata ʹ e : X, f : X -> X Λ͢ͱɺ -- F- (Nat, [Zero, Succ]) ͔Β F- (X, [e, f]) ͷ४ಉܕͱͳΔ nat_cata :: x -> (x -> x) -> Nat -> x nat_cata e _ Zero = e nat_cata e f (Succ n) = f (nat_cata e f n)
r | Yield o (Stream i o r) | Await (i -> Stream i o r) stream_cata :: (r -> x) -> (o -> x -> x) -> ((i -> x) -> x) -> Stream i o r -> x stream_cata df _ _ (Done r) = df r stream_cata df yf af (Yield o s) = yf o (stream_cata df yf af s) stream_cata df yf af (Await f) = af (stream_cata df yf af . f) • ͢͜͠ෳࡶͳྫ
r = Pair l r | Swap (Swap r l) -- ୈೋҾͷܕ͕͜ΕͰ͍͍ͷ͔Θ͔Βͳ͍ swap_cata :: (l -> r -> x) -> (x -> x) -> Swap l r -> x swap_cata pf _ (Pair l r) = pf l r swap_cata pf sf (Swap sw) = sf (swap_cata (swap pf) sf sw)
• nLab (ֶʹಛԽͨ͠ Wikipedia Έ͍ͨͳͷ) ͷ͍Ζ͍Ζͳ߲ • http://ncatlab.org/nlab/show/HomePage • Benjamin C. Pierce, Basic Category Theory for Computer Scientists, 1991 • Steve Awodey, Category Theory, 2010