From 8a5f22fb97e8a578cadac600c1511a9a6a8e5d8b Mon Sep 17 00:00:00 2001 From: Yann Esposito Date: Mon, 10 Dec 2012 12:14:22 +0100 Subject: [PATCH] temporary clean --- categories.html | 87 +++++++++---------- ...=> 040_From_a_Programmer_perspective.html} | 0 ...d => 040_From_a_Programmer_perspective.md} | 0 ...tml => 050_Math_Programming_relation.html} | 0 ...on.md => 050_Math_Programming_relation.md} | 0 ...50_Vocabulary.html => 060_Vocabulary.html} | 0 .../{050_Vocabulary.md => 060_Vocabulary.md} | 0 ...n.html => 070_Programmer_Translation.html} | 2 +- ...ation.md => 070_Programmer_Translation.md} | 2 +- .../160_Degenerated_Categories_Monoids.html | 6 +- .../170_Degenerated_Categories_Preorders.html | 6 +- .../20_What/190_Categorical_Property.html | 7 +- categories/20_What/192.html | 3 + categories/20_What/192.md | 9 ++ .../20_What/210_Functor_Example_ob_ob.html | 2 +- .../20_What/220_Functor_Example_hom_hom.html | 2 +- categories/20_What/230_Functor_Example.html | 2 +- categories/30_How/030_Haskell_Kinds.html | 11 +-- categories/30_How/030_Haskell_Kinds.md | 14 +-- categories/30_How/040_Haskell_Types.html | 1 - categories/30_How/040_Haskell_Types.md | 4 - .../010_Haskell_Functor_vs_Hask_Functor.html | 6 +- .../030_Haskell_Functors_Example_List.html | 6 +- ...0_Haskell_Functors_for_the_programmer.html | 2 +- ...040_Haskell_Functors_for_the_programmer.md | 2 +- .../110_Also_Functor_inside_Hask.html | 2 +- .../120_Category_of_Hask_Endofunctors.html | 2 +- .../120_Category_of_Hask_Endofunctors.md | 2 +- .../130_Category_of_Functors.html | 7 +- .../100_Functors/130_Category_of_Functors.md | 6 -- categories/30_How/100_Functors/140.html | 4 + categories/30_How/100_Functors/140.md | 10 +++ ...0_Natural_Transformation_Examples_1_4.html | 2 +- ...010_Natural_Transformation_Examples_1_4.md | 2 +- ...0_Natural_Transformation_Examples_2_4.html | 2 +- ...020_Natural_Transformation_Examples_2_4.md | 2 +- ...0_Natural_Transformation_Examples_3_4.html | 2 +- ...030_Natural_Transformation_Examples_3_4.md | 2 +- ...0_Natural_Transformation_Examples_4_4.html | 2 +- ...040_Natural_Transformation_Examples_4_4.md | 2 +- ... => 030_morphism_fold_generalization.html} | 0 ...md => 030_morphism_fold_generalization.md} | 0 ...=> 040_morphism_example_with_strings.html} | 0 ...d => 040_morphism_example_with_strings.md} | 0 ...=> 050_morphism_example_with_strings.html} | 0 ...d => 050_morphism_example_with_strings.md} | 0 categories/head.html | 2 +- categories/tail.html | 2 +- themes/style/y/main.css | 20 ++++- themes/style/y/main.sass | 16 +++- 50 files changed, 137 insertions(+), 126 deletions(-) rename categories/10_Introduction/{035.html => 040_From_a_Programmer_perspective.html} (100%) rename categories/10_Introduction/{035.md => 040_From_a_Programmer_perspective.md} (100%) rename categories/10_Introduction/{040_Math_Programming_relation.html => 050_Math_Programming_relation.html} (100%) rename categories/10_Introduction/{040_Math_Programming_relation.md => 050_Math_Programming_relation.md} (100%) rename categories/10_Introduction/{050_Vocabulary.html => 060_Vocabulary.html} (100%) rename categories/10_Introduction/{050_Vocabulary.md => 060_Vocabulary.md} (100%) rename categories/10_Introduction/{060_Translation.html => 070_Programmer_Translation.html} (95%) rename categories/10_Introduction/{060_Translation.md => 070_Programmer_Translation.md} (94%) create mode 100644 categories/20_What/192.html create mode 100644 categories/20_What/192.md create mode 100644 categories/30_How/100_Functors/140.html create mode 100644 categories/30_How/100_Functors/140.md rename categories/30_How/300_Catamorphisms/{030.html => 030_morphism_fold_generalization.html} (100%) rename categories/30_How/300_Catamorphisms/{030.md => 030_morphism_fold_generalization.md} (100%) rename categories/30_How/300_Catamorphisms/{040.html => 040_morphism_example_with_strings.html} (100%) rename categories/30_How/300_Catamorphisms/{040.md => 040_morphism_example_with_strings.md} (100%) rename categories/30_How/300_Catamorphisms/{050.html => 050_morphism_example_with_strings.html} (100%) rename categories/30_How/300_Catamorphisms/{050.md => 050_morphism_example_with_strings.md} (100%) diff --git a/categories.html b/categories.html index 7b739a2..6c6a9fd 100644 --- a/categories.html +++ b/categories.html @@ -16,7 +16,7 @@ - + @@ -134,7 +134,7 @@

Programmer Translation

lolcat - +
Mathematician @@ -374,23 +374,19 @@ such that for each \(f:A→B\):

Each Monoid \((M,e,⊙): \ob{M}=\{∙\},\hom{M}=M,\circ = ⊙\)

Only one object.

Examples:

-
  • (Integer,0,+), -
  • (Integer,1,*), -
  • (Strings,"",++), -
  • for each a, ([a],[],++) +
    • (Integer,0,+), (Integer,1,*), +
    • (Strings,"",++), for each a, ([a],[],++)
    -

    Degenerated Categories: Preorders

    - -

    each preorder \((P,≤)\):

    +

    Degenerated Categories: Preorders \((P,≤)\)

    • \(\ob{P}={P}\),
    • \(\hom{x,y}=\{x≤y\} ⇔ x≤y\),
    • \((y≤z) \circ (x≤y) = (x≤z) \)
    -

    At most one morphism between two objects.

    +

    At most one morphism between two objects.

    preorder category
    @@ -403,14 +399,11 @@ such that for each \(f:A→B\):

    Only identities

    -

    Categorical Property

    +

    Categorical Properties

    Any property which can be expressed in term of category, objects, morphism and composition.

    -
    • isomorphism: \(f:A→B\) which can be "undone" i.e. -
      \(∃g:B→A\), \(g∘f=id_A\) & \(f∘g=id_B\) -
      in this case, \(A\) & \(B\) are isomorphic. -
    • Dual: \(\D\) is \(\C\) with reversed morphisms. +
      • Dual: \(\D\) is \(\C\) with reversed morphisms.
      • Initial: \(Z\in\ob{\C}\) s.t. \(∀Y∈\ob{\C}, \#\hom{Z,Y}=1\)
        Unique ("up to isormophism")
      • Terminal: \(T\in\ob{\C}\) s.t. \(T\) is initial in the dual of \(\C\) @@ -419,6 +412,11 @@ such that for each \(f:A→B\):

    +

    Isomorph

    +

    isomorphism: (f:A→B) which can be "undone" i.e.
    \(∃g:B→A\), \(g∘f=id_A\) & \(f∘g=id_B\)
    in this case, \(A\) & \(B\) are isomorphic.

    +

    In Category Theory, = is generally . For example in commutative diagrams.

    +
    +

    Functor

    A functor is a mapping between two categories. @@ -438,17 +436,17 @@ A functor \(\F\) from \(

    Functor Example (ob → ob)

    -Functor +Functor

    Functor Example (hom → hom)

    -Functor +Functor

    Functor Example

    -Functor +Functor

    Endofunctors

    @@ -500,18 +498,14 @@ A functor \(\F\) from \(

    Haskell Kinds

    In Haskell some types can take type variable(s). Typically: [a].

    -
    data Tree a = Node a [Tree a]
    -data CTree a b = CNode a [b]
    -

    Types have kind; The kind is to type what type is to function. Kind are the types for types (so meta).

    +

    Types have kinds; The kind is to type what type is to function. Kind are the types for types (so meta).

    Int, Char :: *
    -[], Maybe, Tree :: * -> *
    -CTree :: * -> * -> *
    -[Int], Maybe Char, Tree [Int] :: *
    -CTree [Int] :: * -> *
    +[], Maybe :: * -> * +(,) :: * -> * -> * +[Int], Maybe Char, Maybe [Int] :: *

    Haskell Types

    -

    We can make function that can work for all type parameter. Such function can only work with the topology induced by the type. We know such function won't work on the elements.

    Sometimes, the type determine a lot about the function:

    fst :: (a,b) -> a -- Only one choice
     snd :: (a,b) -> b -- Only one choice
    @@ -530,12 +524,12 @@ addOne l = map (+1) l
     

    Haskell Functor vs \(\Hask\) Functor

    -

    Functor for Haskell language is a type F :: * -> * which belong to the type class Functor.
    -It must implement fmap :: (a -> b) -> (F a -> F b). +

    A Haskell Functor is a type F :: * -> * which belong to the type class Functor ; thus instantiate +fmap :: (a -> b) -> (F a -> F b).

    & F: \(\ob{\Hask}→\ob{\Hask}\)
    & fmap: \(\hom{\Hask}→\hom{\Hask}\) -

    The couple (F,fmap) is a functor in the categorical sense for \(\Hask\) if for any x :: F a:

    +

    The couple (F,fmap) is a \(\Hask\) endofunctor if for any x :: F a:

    • fmap id x = x
    • fmap (f.g) x= (fmap f . fmap g) x
    @@ -556,22 +550,20 @@ fmap head (Just [1,2,3]) == Just 1

    Haskell Functors Example: List

    -
    
    -instance Functor ([]) where
    +
    instance Functor ([]) where
         fmap :: (a -> b) -> [a] -> [b]
         fmap = map
     
     fmap (+1) [1,2,3]           == [2,3,4]
     fmap (+1) []                == []
    -fmap head [[1,2,3],[4,5,6]] == [1,4]
    -
    +fmap head [[1,2,3],[4,5,6]] == [1,4]

    Haskell Functors for the programmer

    Functor is a type class used for types that can be mapped over.

    • Containers: [], Trees, Map, HashMap...
    • -
    • Smart containers: +
    • "Feature Type":
      • Maybe a: help to handle absence of a.
        Ex: safeDiv x 0 ⇒ Nothing
      • Either String a: help to handle errors
        Ex: reportDiv x 0 ⇒ Left "Division by 0!"
      • @@ -633,7 +625,7 @@ Haskell types is fractal:

    Also Functor inside \(\Hask\)

    -

    \(\mathtt{[a]}∈\ob{\Hask}\) but is also a complete category. The same can be said for Int.

    +

    \(\mathtt{[a]}∈\ob{\Hask}\) but is also a category. Idem for Int.

    length is a Functor from the category [a] to the cateogry Int:

    • \(\ob{\mathtt{[a]}}=\{∙\}\)
    • @@ -653,26 +645,27 @@ Haskell types is fractal:

    Category of \(\Hask\) Endofunctors

    -Category of Hask endofunctors +Category of Hask endofunctors

    Category of Functors

    If \(\C\) is small (\(\hom{\C}\) is a set). All functors from \(\C\) to some category \(\D\) form the category \(\mathrm{Func}(\C,\D)\).

    -Natural transformation commutative diagram
    • \(\ob{\mathrm{Func}(\C,\D)}\): Functors \(F:\C→\D\)
    • -
    • \(\hom{\mathrm{Func}(\C,\D)}\): natural transformations -
        -
      • η familly \(η_X\in\hom{\D}\) for \(X\in\ob{\C}\) s.t.
      • -
      • ex: between Haskel functors; F a -> G a
        Rearragement functions only.
      • -
    • +
    • \(\hom{\mathrm{Func}(\C,\D)}\): natural transformations
    • ∘: Functor composition

    \(\mathrm{Func}(\C,\C)\) is the category of endofunctors of \(\C\).

    +

    Natural Transformations

    +

    Let \(F\) and \(G\) be two functors from \(\C\) to \(\D\).

    +

    Natural transformation commutative diagram A natural transformation: familly η ; \(η_X\in\hom{\D}\) for \(X\in\ob{\C}\) s.t.

    +

    ex: between Haskell functors; F a -> G a
    Rearragement functions only.

    +
    +

    Natural Transformation Examples (1/4)

    -
    data Tree a = Empty | Node a [Tree a]
    +
    data Tree a = Empty | Node a [Tree a]
     toTree :: [a] -> Tree a
     toTree [] = Empty
     toTree (x:xs) = Node x [toTree xs]
    @@ -687,7 +680,7 @@ toTree (x:xs) = Node x [toTree xs]

    Natural Transformation Examples (2/4)

    -
    data Tree a = Empty | Node a [Tree a]
    +
    data Tree a = Empty | Node a [Tree a]
     toList :: Tree a -> [a]
     toList Empty = []
     toList (Node x l) = [x] ++ concat (map toList l)
    @@ -702,7 +695,7 @@ toList (Node x l) = [x] ++ concat (map toList l)

    Natural Transformation Examples (3/4)

    -
    toMaybe :: [a] -> Maybe a
    +
    toMaybe :: [a] -> Maybe a
     toMaybe [] = Nothing
     toMaybe (x:xs) = Just x
    @@ -716,7 +709,7 @@ toMaybe (x:xs) = Just x

    Natural Transformation Examples (4/4)

    -
    mToList :: Maybe a -> [a]
    +
    mToList :: Maybe a -> [a]
     mToList Nothing = []
     mToList Just x  = [x]
    @@ -997,7 +990,7 @@ depth = cata phi where - + - +