675 lines
22 KiB
HTML
675 lines
22 KiB
HTML
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||
<meta name="viewport" content="width=1024, user-scalable=no">
|
||
|
||
<title>Category Theory for Programming</title>
|
||
|
||
<!-- Required stylesheet -->
|
||
<link rel="stylesheet" href="core/deck.core.css">
|
||
|
||
<!-- Extension CSS files go here. Remove or add as needed. -->
|
||
<link rel="stylesheet" href="extensions/goto/deck.goto.css">
|
||
<link rel="stylesheet" href="extensions/menu/deck.menu.css">
|
||
<link rel="stylesheet" href="extensions/navigation/deck.navigation.css">
|
||
<link rel="stylesheet" href="extensions/status/deck.status.css">
|
||
<link rel="stylesheet" href="extensions/hash/deck.hash.css">
|
||
<link rel="stylesheet" href="extensions/scale/deck.scale.css">
|
||
|
||
<!-- Transition theme. More available in /themes/transition/ or create your own. -->
|
||
|
||
<link rel="stylesheet" href="themes/transition/fade.css">
|
||
<!-- Style theme. More available in /themes/style/ or create your own. -->
|
||
<!-- <link rel="stylesheet" href="themes/style/web-2.0.css"> -->
|
||
<link rel="stylesheet" href="themes/style/y/main.css" />
|
||
<link rel="stylesheet" href="themes/style/y/solarized.css" />
|
||
|
||
<!-- Required Modernizr file -->
|
||
<script src="modernizr.custom.js"></script>
|
||
|
||
</head>
|
||
<body class="deck-container">
|
||
|
||
<div style="display:none">
|
||
\(\newcommand{\F}{\mathbf{F}}\)
|
||
\(\newcommand{\C}{\mathcal{C}}\)
|
||
\(\newcommand{\D}{\mathcal{D}}\)
|
||
\(\newcommand{\id}{\mathrm{id}}\)
|
||
\(\newcommand{\ob}[1]{\mathrm{ob}(#1)}\)
|
||
\(\newcommand{\hom}[1]{\mathrm{hom}(#1)}\)
|
||
\(\newcommand{\Set}{\mathbf{Set}}\)
|
||
\(\newcommand{\Mon}{\mathbf{Mon}}\)
|
||
\(\newcommand{\Vec}{\mathbf{Vec}}\)
|
||
\(\newcommand{\Grp}{\mathbf{Grp}}\)
|
||
\(\newcommand{\Rng}{\mathbf{Rng}}\)
|
||
\(\newcommand{\ML}{\mathbf{ML}}\)
|
||
\(\newcommand{\Hask}{\mathbf{Hask}}\)
|
||
</div>
|
||
|
||
|
||
<!-- Begin slides. Just make elements with a class of slide. -->
|
||
|
||
<section class="slide">
|
||
<h1>Category Theory <span class="and"><span class="and">&</span></span> Programming
|
||
<div><author style="font-size: .4em"><em class="base01">by</em> Yann Esposito
|
||
<div style="font-size:.5em">
|
||
<twitter>
|
||
<a href="http://twitter.com/yogsototh">@yogsototh</a>,
|
||
</twitter>
|
||
<googleplus>
|
||
<a href="https://plus.google.com/117858550730178181663">+yogsototh</a>
|
||
</googleplus>
|
||
</div>
|
||
</author></div>
|
||
<div class="base01" style="font-size: .25em; font-weight: 400; font-variant:italic">
|
||
HTML presentation: use arrows, space to navigate.
|
||
</div>
|
||
</h1>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Plan</h2>
|
||
<ul style="font-size: 2em; font-weight:bold">
|
||
<li><span class="yellow">Why?
|
||
<ul class="base01" style="border-left: 2px solid; padding-left: 1em; font-size: .6em; float: right; font-weight: bold; margin: 0 0 0 1em">
|
||
<li>Math <span class="and"><span class="and">&</span></span> Abstraction</li>
|
||
<li>Programming <span class="and"><span class="and">&</span></span> Abstraction</li>
|
||
<li>Categories <span class="and"><span class="and">&</span></span> Abstraction</li>
|
||
</ul>
|
||
</li>
|
||
<li>What?</li>
|
||
<li>How?</li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Abstraction</h2>
|
||
<p>A common concept you see often in multiple instances.</p>
|
||
<div>
|
||
<p>Numbers: 1,2,3,... <em class="small">3400 BC, real numbers 760 BC</em></p>
|
||
<figure class="left">
|
||
<img src="categories/img/tally-count.png" style="height:5em" alt="Aboriginal Tally System"/>
|
||
<figcaption>Aboriginal Tally System</figcaption>
|
||
</figure>
|
||
<div>
|
||
<div class="left" style="left-margin: 1em">amelioration ⇒</div>
|
||
<figure class="left">
|
||
<img src="categories/img/first-real-numbers.png" style="height:5em" alt="Mesopotamian Numbers"/>
|
||
<figcaption>Mesopotamian base 60 system</figcaption>
|
||
</figure>
|
||
</div>
|
||
<div class="flush"></div>
|
||
<div>
|
||
Operators: <b>=, <, >, +, ×, ...</b>
|
||
</div>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Generalization</h2>
|
||
<div class="right">
|
||
<img src="categories/img/egyptian-hieroglyphics.jpg" alt="Egyptian Fractions"/>
|
||
<img src="categories/img/negative-numbers.jpg" alt="Negative Numbers (Chinese)"/>
|
||
</div>
|
||
<ul><li> Weight/Distance/Time ⇒ <em>Rational</em> \(\frac{p}{q}\)
|
||
</li><li> Debts ⇒ <em>Negative</em> \(..., -2, -1, ? , 1, 2, ...\)
|
||
</li><li> Geometry ⇒ <em>Irrational<sup style="vertical-align:middle">*</sup></em>
|
||
</li><li> Algebra ⇒ <em>Complex</em>
|
||
</li><li> \(0\) ⇒ "Nothing" become a number
|
||
</li></ul>
|
||
<p><span class="and" style="visibility:hidden"><span class="and">&</span></span> More <strong>things</strong> can be understood as numbers<br/>
|
||
<span class="and"><span class="and">&</span></span> More <strong>operator</strong> to manipulate them.</p>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Numbers ⇒ Sets</h2>
|
||
<table>
|
||
<tr>
|
||
<th>Numbers</th>
|
||
<th>Set Theory (∞)/Abstract Algebra/Topology</th>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{N}\): \((+,0)\)</td>
|
||
<td>Semigroups</td>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{Z}\): \((+,0,\times,1)\)</td>
|
||
<td>Rings</td>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{Q}\)</td>
|
||
<td>Fields</td>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{R}\)</td>
|
||
<td>Complete Fields (<em class="base01">topology</em>)</td>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{C}\)</td>
|
||
<td>Algebræ</td>
|
||
</tr>
|
||
<tr><td></td><td>Modules,Vector Spaces, Monoids, ...</td></tr>
|
||
</table>
|
||
<p><span class="and" style="visibility:hidden"><span class="and">&</span></span> More <strong>general</strong>: more things are sets.<br/>
|
||
<span class="and"><span class="and">&</span></span> More <strong>precise</strong>: clear distinction between concepts.</p>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Sets ⇒? <span class="yellow">Categories</span></h2>
|
||
<table>
|
||
<tr>
|
||
<th>Numbers</th>
|
||
<th>Sets</th>
|
||
<th>Categories</th>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{N}\): \((+,0)\)</td>
|
||
<td>Semigroups</td>
|
||
<td>?</td>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{Z}\): \((+,0,\times,1)\)</td>
|
||
<td>Rings</td>
|
||
<td>?</td>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{Q}\)</td>
|
||
<td>Fields</td>
|
||
<td>?</td>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{R}\)</td>
|
||
<td>Complete Fields (<em class="base01">topology</em>)</td>
|
||
<td>?</td>
|
||
</tr>
|
||
<tr>
|
||
<td>\(\mathbb{C}\)</td>
|
||
<td>Algebræ</td>
|
||
<td>?</td>
|
||
</tr>
|
||
<tr><td></td><td>Modules,Vector Spaces, Monoids, ...</td><td>?</td></tr>
|
||
</table>
|
||
</section>
|
||
<section class="slide">
|
||
<h2><span class="yellow">/.*/</span> ⇒? Category Theory</h2>
|
||
<p>Gate between different scientific fields</p>
|
||
<ul>
|
||
<li>Topology</li>
|
||
<li>Quantum Physics</li>
|
||
<li>Logic</li>
|
||
<li><b>Programming</b></li>
|
||
</ul>
|
||
<p><span class="and" style="visibility:hidden"><span class="and">&</span></span> More <strong>general</strong>: more things are Categories.<br/>
|
||
<span class="and"><span class="and">&</span></span> More <strong>precise</strong>: better distinction between concepts.</p>
|
||
<p>Young field: <b>1942–45</b>, Samuel Eilenberg <span class="and"><span class="and">&</span></span> Saunders Mac Lane
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Programming <span class="and"><span class="and">&</span></span> Abstraction</h2>
|
||
|
||
<h3>Impure programming</h3>
|
||
<ul>
|
||
<li>Encouraged by imperative paradigms.
|
||
</li><li>Actions <span class="and"><span class="and">&</span></span> mutable objects.
|
||
</li><li>Time is <em>very</em> important: ex. linked list push
|
||
</li><li>Synchronizing things is a challenge.
|
||
</li>
|
||
</ul>
|
||
<p>Natural Abstractions: pointers, variables, loop, Objects, Classes...</p>
|
||
<p>Representation: a data structure changing other time.</p>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Untyped Pure Programming</h2>
|
||
|
||
<ul><li> Time is irrelevant by default.
|
||
</li><li> Mostly static constructions like pipes.
|
||
</li><li> All pipes are round ⇒ all error at runtime
|
||
<ul><li> (+ ("foo" 27) 32)
|
||
</li><li> Y = λf.(λx.f (x x)) (λx.f (x x))
|
||
</li><li> Y g = g (Y g)
|
||
</li></ul>
|
||
</li></ul>
|
||
|
||
<p>Natural abstraction: higher level functions <span class="and"><span class="and">&</span></span> equations</p>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Strongly Typed Pure Programming</h2>
|
||
<ul><li>Add specific forms on pipes.
|
||
<ul><li> <code class="red">4 + ["foo",27]</code> forbidden
|
||
</li><li> <code class="red">["foo",27]</code> forbidden
|
||
</li></ul>
|
||
</li><li>Pipe can contains other pipes.
|
||
<ul><li> <code>data Maybe a = Just a | Nothing</code>
|
||
</li><li> <code>[Just 32,Nothing,Just 12] :: [Maybe Integer]</code>
|
||
</li></ul>
|
||
</li></ul>
|
||
<p>Natural abstraction: Polymorphic higher level functions.</p>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Polymorphism: <code>mappend</code></h2>
|
||
|
||
<h3><code>(<>) = `mappend`</code></h3>
|
||
<pre class="haskell"><code>"abc" <> "def" = "abcdef"
|
||
("abc","xyz") <> ("ABC","XYZ") = ("abcABC","xyzXYZ")
|
||
3 <> 4 = ERROR which law? + or *
|
||
-- Monoid (N,+)
|
||
type Sum = Sum {getSum :: a}
|
||
(<>+) = getSum (Sum x <> Sum y)
|
||
3 <>+ 4 = 7
|
||
-- Monoid (N,*)
|
||
type Product = Product {getProduct :: a}
|
||
(<>*) = getProduct (Product x <> Product y)
|
||
3 <>* 4 = 12</code></pre>
|
||
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Polymorphism: <code>(>>=)</code></h2>
|
||
|
||
<p>Example: <span class="red"><code>(>>=)</code></span> with <code>[a]</code> and <code>Maybe a</code></p>
|
||
<pre class="haskell"><code>data Maybe a = Just a | Nothing</code></pre>
|
||
|
||
<pre class="haskell"><code>-- Maybe : Maybe Int >>= Int -> Maybe (Int -> Int) >>= (Int -> Int) -> Maybe Int
|
||
(Just 2) <span class="red">>>=</span> \x -> (Just (\z->z*z)) <span class="red">>>=</span> \f -> Just (f x) = Just 4
|
||
Nothing <span class="red">>>=</span> \x -> (Just (\z->z*z)) <span class="red">>>=</span> \f -> Just (f x) = Nothing
|
||
|
||
-- Lists: [a] : [Int] >>= Int -> [Int -> Int] >>= (Int -> Int) -> [Int]
|
||
[1,2] <span class="red">>>=</span> \x -> [(+10),(+20)] <span class="red">>>=</span> \f -> [f x] = [11,21,12,22]
|
||
[] <span class="red">>>=</span> \x -> [(+10),(+20)] <span class="red">>>=</span> \f -> [f x] = []</code></pre>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Programming Paradigms</h2>
|
||
<table>
|
||
<tr><td>Impure</td><td>Choose the data structure, find an algorithm.</td></tr>
|
||
<tr><td>Untyped Pure</td><td>Choose the data structure, find an equation.</td></tr>
|
||
<tr><td>Typed Pure</td><td>Choose the Types and their laws, find the right operator</td></tr>
|
||
</table>
|
||
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Type Theory ⇒ Categories</h2>
|
||
|
||
<ul>
|
||
<li>Type theory helped to remove paradoxes in Set Theory.</li>
|
||
<li>Prevent relations between different kind of objects.</li>
|
||
<li>Used in computer science</li>
|
||
</ul>
|
||
|
||
<ul>
|
||
<li>typed λ-calculus ⇒ cartesian closed categories</li>
|
||
<li>untyped λ-calculus ⇒ C-monoids (subclass of categories)</li>
|
||
<li>Martin-Löf type theories ⇒ locally cartesian closed categories</li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Plan</h2>
|
||
<ul style="font-size: 2em; font-weight: bold">
|
||
<li>Why?</li>
|
||
<li> <span class="yellow">What?</span>
|
||
<ul class="base01" style="border-left: 2px solid; padding-left: 1em; font-size: .6em; float: right; font-weight: bold; margin: 0 0 0 1em">
|
||
<li>Category</li>
|
||
<li>Intuition</li>
|
||
<li>Examples</li>
|
||
<li>Functor</li>
|
||
<li>Examples</li>
|
||
</ul>
|
||
</li>
|
||
<li>How?</li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Category</h2>
|
||
|
||
<p>A way of representing <strong><em>things</em></strong> and <strong><em>ways to go between things</em></strong>.</p>
|
||
|
||
<p> A Category \(\mathcal{C}\) is defined by:</p>
|
||
<ul>
|
||
<li> <em>Objects (\(\ob{C}\))</em>,</li>
|
||
<li> <em>Morphisms (\(\hom{C}\))</em>,</li>
|
||
<li> a <em>Composition law (∘)</em></li>
|
||
<li> obeying some <em>Properties</em>.</li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Category: Objects</h2>
|
||
|
||
<img src="categories/img/mp/objects.png" alt="objects" />
|
||
|
||
<p>\(\ob{\mathcal{C}}\) is a collection</p>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Category: Morphisms</h2>
|
||
|
||
<img src="categories/img/mp/morphisms.png" alt="morphisms"/>
|
||
|
||
<p>\(\hom{A,B}\) is a collection</p>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Category: Composition</h2>
|
||
<p>Composition (∘): \(f:A→B, g:B→C\)
|
||
$$g∘f:A\rightarrow C$$
|
||
</p>
|
||
<img src="categories/img/mp/composition.png" alt="composition"/>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Category laws: neutral element</h2>
|
||
<p>for all \(X\), there is an \(\id_X\), s.t. for all \(f:A→B\):</p>
|
||
<img src="categories/img/mp/identity.png" alt="identity"/>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Category laws: Associativity</h2>
|
||
<p> Composition is associative:</p>
|
||
<img src="categories/img/mp/associativecomposition.png" alt="associative composition"/>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Commutative diagrams</h2>
|
||
|
||
<p>Two path with the same source and destination are equal.</p>
|
||
<figure class="left" style="max-width: 40%;margin-left: 10%;">
|
||
<img
|
||
src="categories/img/mp/commutative-diagram-assoc.png"
|
||
alt="Commutative Diagram (Associativity)"/>
|
||
<figcaption>
|
||
\((h∘g)∘f = h∘(g∘f) \)
|
||
</figcaption>
|
||
</figure>
|
||
<figure class="right" style="max-width:31%;margin-right: 10%;">
|
||
<img
|
||
src="categories/img/mp/commutative-diagram-id.png"
|
||
alt="Commutative Diagram (Identity law)"/>
|
||
<figcaption>
|
||
\(id_B∘f = f = f∘id_A \)
|
||
</figcaption>
|
||
</figure>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Can this be a category?</h2>
|
||
<figure class="left">
|
||
<img src="categories/img/mp/cat-example1.png" alt="Category example 1"/>
|
||
<figcaption class="slide">
|
||
<span class="green">YES</span>
|
||
</figcaption>
|
||
</figure>
|
||
<figure class="left">
|
||
<img src="categories/img/mp/cat-example2.png" alt="Category example 2"/>
|
||
<figcaption class="slide">
|
||
no candidate for \(g∘f\)
|
||
<br/><span class="red">NO</span>
|
||
</figcaption>
|
||
</figure>
|
||
<figure class="left">
|
||
<img src="categories/img/mp/cat-example3.png" alt="Category example 3"/>
|
||
<figcaption class="slide">
|
||
<span class="green">YES</span>
|
||
</figcaption>
|
||
</figure>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Can this be a category?</h2>
|
||
<figure class="left">
|
||
<img src="categories/img/mp/cat-example4.png" alt="Category example 4"/>
|
||
<figcaption class="slide">
|
||
no candidate for \(f:C→B\)
|
||
<br/><span class="red">NO</span>
|
||
</figcaption>
|
||
</figure>
|
||
<figure class="right" style="min-width: 59%">
|
||
<img src="categories/img/mp/cat-example5.png" alt="Category example 5"/>
|
||
<figcaption class="slide">
|
||
\((h∘g)∘f=\id_B∘f=f\)<br/>
|
||
\(h∘(g∘f)=h∘\id_A=h\)<br/>
|
||
but \(h≠f\)<br/>
|
||
<span class="red">NO</span>
|
||
</figcaption>
|
||
</figure>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Categories Everywhere?</h2>
|
||
|
||
<h3>\(\Set\)</h3>
|
||
<ul>
|
||
<li> \(\ob{\Set}\) are sets</li>
|
||
<li> \(\hom{\Set}\) are functions</li>
|
||
<li> ∘ is functions composition </li>
|
||
</ul>
|
||
|
||
<ul class="slide">
|
||
<li>\(\ob{\Set}\) is a proper class ; not a set</li>
|
||
<li>\(\hom{E,F}\) is a set</li>
|
||
<li>\(\Set\) is a <em>locally small category</em></li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Categories Everywhere?</h2>
|
||
|
||
<ul>
|
||
<li>\(\Mon\): (monoids, monoid morphisms,∘)</li>
|
||
<li>\(\Vec\): (Vectorial spaces, linear functions,∘)</li>
|
||
<li>\(\Grp\): (groups, group morphisms,∘)</li>
|
||
<li>\(\Rng\): (rings, ring morphisms,∘)</li>
|
||
<li>\( \ML\): (types, terms, \(λg. λf. λx. g f x\) )</li>
|
||
<li>...</li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Smaller Examples</h2>
|
||
|
||
<h3>Strings</h3>
|
||
<img class="right" style="max-width:17%" src="categories/img/mp/strings.png" alt="Monoids are one object categories"/>
|
||
<ul>
|
||
<li> \(\ob{Str}\) is a singleton </li>
|
||
<li> \(\hom{Str}\) each string </li>
|
||
<li> ∘ is concatenation <code>(++)</code> </li>
|
||
</ul>
|
||
<ul>
|
||
<li> <code>"" ++ u = u = u ++ ""</code> </li>
|
||
<li> <code>(u ++ v) ++ w = u ++ (v ++ w)</code> </li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Finite Example?</h2>
|
||
|
||
<h3>Graph</h3>
|
||
<figure class="right" style="max-width:40%" >
|
||
<img src="categories/img/mp/graph-category.png" alt="Each graph is a category"/>
|
||
<figcaption style="text-align:left"><ul><li>\(\ob{G}={X,Y,Z}\),
|
||
</li><li>\(\hom{G}=\{ε,α,β,γ,αβ,βγ,...\}\)<br/>
|
||
\(\phantom{\hom{G}}=(βγ?)?(αβγ)^*(αβ?)?\),
|
||
</li><li>\(αβ∘γ=αβγ\)
|
||
</li></ul>
|
||
</figcaption>
|
||
</figure>
|
||
<ul>
|
||
<li> \(\ob{G}\) are vertices</li>
|
||
<li> \(\hom{G}\) each path</li>
|
||
<li> ∘ is path concatenation</li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Degenerated Categories</h2>
|
||
|
||
<img class="right" style="max-width:17%" src="categories/img/mp/monoid.png" alt="Monoids are one object categories"/>
|
||
<h3>Monoids</h3>
|
||
<p>each Monoid \((M,e,◎): \ob{M}=\{∙\},\hom{M}=M,\circ = ◎\)</p>
|
||
<p>one object</p>
|
||
<p>Examples: <code>(Integer,0,+)</code>, <code>(Integer,1,*)</code>, <code>(Strings,"",++)</code>, <code>(Lists,[],++)</code>, ...
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Number construction</h2>
|
||
|
||
<h3>Each Numbers as a whole category</h3>
|
||
<img src="categories/img/mp/numbers.png" alt="Each number as a category"/>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Degenerated Categories</h2>
|
||
|
||
<h3>Preorders</h3>
|
||
<p>each preorder \((P,≤): \ob{P}={P},\hom{x,y}=\{{x≤y}\} ⇔ x≤y,f_{y,z} \circ f_{x,y} = f_{x,z} \)</p>
|
||
<em>At most one morphism between two objects.</em>
|
||
<img src="categories/img/mp/preorder.png" alt="preorder category"/>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Degenerated Categories</h2>
|
||
|
||
<img class="right" src="categories/img/mp/set.png" alt="Any set can be a category"/>
|
||
<h3>Any Set</h3>
|
||
<p>Any set \(E: \ob{E}=E, \hom{x,y}=\{x\} ⇔ x=y \)</p>
|
||
<p><em>Only identities ; not so interesting</em></p>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Functor</h2>
|
||
|
||
<p> A functor is a mapping between two categories.
|
||
Let \(\C\) and \(\D\) be two categories.
|
||
A <em>functor</em> \(\F\) from \(\C\) to \(\D\):</p>
|
||
<ul>
|
||
<li> Associate objects: \(A\in\ob{\C}\) to \(\F(A) \in\ob{\D}\) </li>
|
||
<li> Associate morphisms: \(f:A\to B\) to \(\F(f) : \F(A) \to \F(B)\)
|
||
such that
|
||
<ul>
|
||
<li>\( \F (\id_X) = \id_{\F(X)} \),</li>
|
||
<li>\( \F (g \circ_\C f) = \F(g) \circ_\D \F(f) \)</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Functor Example (ob → ob)</h2>
|
||
|
||
<img src="categories/img/mp/functor.png" alt="Functor"/>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Functor Example (hom → hom)</h2>
|
||
|
||
<img src="categories/img/mp/functor-morphism.png" alt="Functor"/>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Functor Example</h2>
|
||
|
||
<img src="categories/img/mp/functor-morphism-color.png" alt="Functor"/>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Plan</h2>
|
||
<ul style="font-size: 2em; font-weight:bold">
|
||
<li>Why?</li>
|
||
<li>What?</li>
|
||
<li><span class="yellow">How?
|
||
<ul class="base01" style="border-left: 2px solid; padding-left: 1em; font-size: .6em; float: right; font-weight: bold; margin: -2em 0 0 1em">
|
||
<li>\(\Hask\) category
|
||
</li><li> Functors
|
||
</li><li> Monads
|
||
</li><li> Arrows
|
||
</li><li> κατα-morphisms
|
||
</li></ul>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Hask</h2>
|
||
|
||
<p>Category \(\Hask\):</p>
|
||
|
||
<ul><li>
|
||
\(ob(\Hask) = \) Haskell types
|
||
</li><li>
|
||
\(hom(\Hask) = \) Haskell functions
|
||
</li><li>
|
||
∘ = <code>(.)</code> Haskell function composition
|
||
</li></ul>
|
||
|
||
<p>Forget glitches because of <code>undefined</code>.</p>
|
||
</section>
|
||
<section class="slide">
|
||
<h2>Haskell Endofunctors</h2>
|
||
|
||
In \(\Hask\) a functor should transform Haskell types and functions.
|
||
|
||
F :: * -> *
|
||
|
||
Int ===> F Int
|
||
Int -> Int ===> F (Int -> Int)
|
||
[a] ===> F [a]
|
||
F a ===> F (F a)
|
||
|
||
Int -> Int ---(+)---> Int ====> F (Int -> Int) ---- fmap (+) ----> F Int
|
||
|
||
If F Hask included in Hask. F is said to be an endofunctor.
|
||
|
||
<pre class="nohighlight"><code>
|
||
Hask loop F Hask
|
||
|
||
Int ===> F Int
|
||
a -> b ====> F (a -> b)
|
||
...
|
||
</code></pre>
|
||
|
||
In Haskell type of type * -> * works naturally on types.
|
||
|
||
<pre class="haskell"><code>
|
||
data Maybe a = Just a | Nothing -- For example
|
||
x :: Maybe Int
|
||
x = Just 10
|
||
y :: Maybe Int
|
||
y = Nothing
|
||
z :: Maybe ([a] -> a)
|
||
z = Just head
|
||
|
||
data F a = Cons Char a | Nil -- For example
|
||
toto,titi,tata :: F Int
|
||
toto = Cons 'c' 10
|
||
titi = Nil
|
||
tata :: F ([a] -> a)
|
||
tata = Cons 'a' head
|
||
</code></pre>
|
||
</section>
|
||
<!-- End slides. -->
|
||
|
||
|
||
<!-- Begin extension snippets. Add or remove as needed. -->
|
||
|
||
<!-- deck.navigation snippet -->
|
||
<a href="#" class="deck-prev-link" title="Previous">←</a>
|
||
<a href="#" class="deck-next-link" title="Next">→</a>
|
||
|
||
<!-- deck.status snippet -->
|
||
<p class="deck-status">
|
||
<span class="deck-status-current"></span>
|
||
/
|
||
<span class="deck-status-total"></span>
|
||
</p>
|
||
|
||
<!-- deck.goto snippet -->
|
||
<form action="." method="get" class="goto-form">
|
||
<label for="goto-slide">Go to slide:</label>
|
||
<input type="text" name="slidenum" id="goto-slide" list="goto-datalist">
|
||
<datalist id="goto-datalist"></datalist>
|
||
<input type="submit" value="Go">
|
||
</form>
|
||
|
||
<!-- deck.hash snippet -->
|
||
<a href="." title="Permalink to this slide" class="deck-permalink">#</a>
|
||
|
||
<!-- End extension snippets. -->
|
||
|
||
|
||
<!-- Required JS files. -->
|
||
<script src="jquery-1.7.2.min.js"></script>
|
||
<script src="core/deck.core.js"></script>
|
||
|
||
<!-- Extension JS files. Add or remove as needed. -->
|
||
<script src="core/deck.core.js"></script>
|
||
<script src="extensions/hash/deck.hash.js"></script>
|
||
<script src="extensions/menu/deck.menu.js"></script>
|
||
<script src="extensions/goto/deck.goto.js"></script>
|
||
<script src="extensions/status/deck.status.js"></script>
|
||
<script src="extensions/navigation/deck.navigation.js"></script>
|
||
<script src="extensions/scale/deck.scale.js"></script>
|
||
|
||
<!-- Initialize the deck. You can put this in an external file if desired. -->
|
||
<script>
|
||
$(function() {
|
||
$.deck('.slide');
|
||
});
|
||
</script>
|
||
<!-- Y theme -->
|
||
<script src="js/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
|
||
<script src="js/highlight/highlight.pack.js"></script>
|
||
<script>
|
||
hljs.initHighlightingOnLoad();
|
||
</script>
|
||
</body>
|
||
</html>
|