This commit is contained in:
Yann Esposito 2012-11-26 09:48:19 +01:00
parent 3850ef6655
commit 53a6630454
87 changed files with 275 additions and 88 deletions

View file

@ -73,6 +73,7 @@
<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>About this presentation</li>
<li>Math <span class="and"><span class="and">&amp;</span></span> Abstraction</li>
<li>Programming <span class="and"><span class="and">&amp;</span></span> Abstraction</li>
<li>Categories <span class="and"><span class="and">&amp;</span></span> Abstraction</li>
@ -83,8 +84,41 @@
</ul>
</section>
<section class="slide">
<h2 id="about-this-presentation">About this presentation</h2>
<ul>
<li>A lot of slides, but short with pictures,</li>
<li>General Ideas → Definitions → Examples using Haskell,</li>
<li>About very fundamental Math, but I'll try not to digress.</li>
</ul>
</section>
<section class="slide">
<h2 id="category-theory-goal">Category Theory Goal?</h2>
<p>Many different approach about Category Theory:</p>
<ul>
<li><a href="http://math.ucr.edu/home/baez/rosetta.pdf">Homogeneous vocabulary and notations</a></li>
<li><a href="http://math.ucr.edu/home/baez/rosetta.pdf">Bridge between disciplines</a></li>
<li><a href="http://www.math.harvard.edu/~mazur/preprints/when_is_one.pdf">Better definition of equality</a></li>
<li><a href="www.math.harvard.edu/~mazur/preprints/when_is_one.pdf">Generalization by default</a></li>
<li>Better math foundations</li>
</ul>
</section>
<section class="slide">
<h2 id="what-can-category-theory-do-for-us">What can Category Theory do for us?</h2>
<ul>
<li>Ability to see problem differently</li>
<li>Ability to abstract at the right level</li>
<li>Reduce bugs by separating concepts</li>
</ul>
<p>What did they already done?</p>
<ul>
<li>Functors, Applicative Functor, Monads, Arrows</li>
<li>Generalize <code>fold</code></li>
<li>...</li>
</ul>
</section>
<section class="slide">
<h2>Abstraction</h2>
<p>A common concept you see often in multiple instances.</p>
<p>A common concept you see in multiple instances.</p>
<div>
<p>Numbers: 1,2,3,... <em class="small">3400 BC, real numbers 760 BC</em></p>
<figure class="left">
@ -186,7 +220,9 @@
<tr><td></td><td>Modules,Vector Spaces, Monoids, ...</td><td></td></tr>
</table>
<p><span class="and" style="visibility:hidden"><span class="and">&amp;</span></span> More <strong>general</strong>: more things are <span class="yellow">categories</span>.<br/>
<span class="and"><span class="and">&amp;</span></span> More <strong>abstract</strong>: generalization for free; replace = by <span class="yellow"></span>.</p>
<span class="and"><span class="and">&amp;</span></span> More <strong>abstract</strong>: generalization for free; replace = by <span class="yellow"></span>.<br/>
<span class="and"><span class="and">&amp;</span></span> Homogeneous <strong>vocabulary</strong>.
</p>
</section>
<section class="slide">
<h2>Category Theory</h2>
@ -245,28 +281,31 @@
<section class="slide">
<h2>Polymorphism: <code>mappend (<>)</code></h2>
<pre class="haskell"><code>"abc" <> "def" = "abcdef" -- String
("ab","xy") <> ("AB","XY") = ("abAB","xyXY") -- (String,String)
<pre class="small haskell"><code> "abcdef" <span class="red"><></span> "ABCDEF" = "abcdefABCDEF" -- String
("ab","xy") <span class="red"><></span> ("AB","XY") = ("abAB","xyXY") -- (String,String)
3 <span class="red"><></span> 4 ⇒ ERROR which law? + or * -- Int
3 <> 4 ⇒ ERROR which law? + or * -- Int
-- Use a type to remove ambiguity
type Sum = Sum {getSum :: a} -- Just a named box
-- Monoid (N,+)
(<>+) = getSum (Sum x <> Sum y)
-- Monoid (Int,+,0)
(<>+) = getSum (Sum x <span class="red"><></span> Sum y)
3 <>+ 4 = 7
-- Monoid (N,*)
(<>*) = getProduct (Product x <> Product y)
-- Monoid (Int,*,0)
type Product = Product {getProduct :: a} -- Just a named box
(<>*) = getProduct (Product x <span class="red"><></span> Product y)
3 <>* 4 = 12</code></pre>
<p>Note: with Monoids (M,⊙,e); <code>foldl ⊙ e ms = foldr ⊙ e ms</code></p>
</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="small haskell"><code>data Maybe a = Just a | Nothing</code></pre>
<pre class="haskell"><code>-- Maybe Int >>= Int -> Maybe (Int -> Int) >>= (Int -> Int) -> Maybe Int
<pre class="small haskell"><code>-- Maybe Int >>= Int -> Maybe (Int -> Int) >>= (Int -> Int) -> Maybe Int
(Just 2) <span class="red">&gt;&gt;=</span> \x -> (Just (\z->z*z)) <span class="red">&gt;&gt;=</span> \f -> Just (f x) = Just 4
Nothing <span class="red">&gt;&gt;=</span> \x -> (Just (\z->z*z)) <span class="red">&gt;&gt;=</span> \f -> Just (f x) = Nothing
@ -350,7 +389,7 @@ type Sum = Sum {getSum :: a} -- Just a named box
</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>
<p>for each object \(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">
@ -381,6 +420,7 @@ type Sum = Sum {getSum :: a} -- Just a named box
</section>
<section class="slide">
<h2>Can this be a category?</h2>
<p>\(\ob{\C},\hom{\C}\) fixed, is there a valid ∘?</p>
<figure class="left">
<img src="categories/img/mp/cat-example1.png" alt="Category example 1"/>
<figcaption class="slide">
@ -443,7 +483,6 @@ type Sum = Sum {getSum :: a} -- Just a named box
<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>\( \Hask\): (Haskell types, functions, <code>(.)</code> )</li>
<li>...</li>
</ul>
@ -486,7 +525,7 @@ type Sum = Sum {getSum :: a} -- Just a named box
<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>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>
@ -603,18 +642,43 @@ A <em>functor</em> \(\F\) from \(\C\) to \(\D\):</p>
</li></ul>
<p>Forget glitches because of <code>undefined</code>.</p>
</section>
<section class="slide">
<h2 id="haskell-kinds">Haskell Kinds</h2>
<p>In Haskell some types can take type variable. Typically: <code>[a]</code>.</p>
<pre><code>data Tree a = Node a [Tree a]
data CTree a b = CNode a [b]</code></pre>
<p>Types have <em>kind</em>; The kind is to type what type is to function. Kind are the &quot;type&quot; for some types (so meta).</p>
<pre><code>Int, Char :: *
[], Maybe, Tree :: * -&gt; *
CTree :: * -&gt; * -&gt; *
[Int], Maybe Char, Tree [Int] :: *</code></pre>
</section>
<section class="slide">
<h2 id="haskell-types">Haskell Types</h2>
<p>We can make function that can work for <em>all</em> type parameter. Such function can only work with the <em>topology</em> induced by the type. We know such function won't work <em>on</em> the elements.</p>
<p>Sometimes, the type determine a lot about the function:</p>
<pre class="haskell"><code>fst :: (a,b) -> a -- Only one choice
snd :: (a,b) -> b -- Only one choice
f :: a -> [a] -- Many choices
-- Possibilities: f x=[], or [x], or [x,x] or [x,...,x]
? :: [a] -> [a] -- Many choices
-- can only duplicate/remove/reorder elements
-- for example: the type of addOne isn't [a] -> [a]
addOne l = map (+1) l</code></pre>
</section>
<section class="slide">
<h2>Haskell Functor vs \(\Hask\) Functor</h2>
<p>Functor for Haskell language is a type <code>F :: * -> *</code> which belong to the type class <code>Functor</code></p>
<p>It must implement <code>fmap :: (a -> b) -> (F a -> F b)</code>.
<p>Functor for Haskell language is a type <code>F :: * -> *</code> which belong to the type class <code>Functor</code>.<br/>
It must implement <code>fmap :: (a -> b) -> (F a -> F b)</code>.
<p><code>F</code>: \(\ob{\Hask}→\ob{\Hask}\) and <code>fmap</code>: \(\hom{\Hask}→\hom{\Hask}\)
<p><span style="visibility:hidden"><span class="and">&amp;</span></span> <code>F</code>: \(\ob{\Hask}→\ob{\Hask}\)<br/> <span class="and">&amp;</span> <code>fmap</code>: \(\hom{\Hask}→\hom{\Hask}\)
<p>The couple <code>(F,fmap)</code> is then a real functor in the categorical sense for \(\Hask\) if</p>
<p>for any <code>x :: F a</code>:</p>
<p>The couple <code>(F,fmap)</code> is a functor in the categorical sense for \(\Hask\) if for any <code>x :: F a</code>:</p>
<ul><li><code>fmap id x = x</code>
</li><li><code>fmap (f.g) x= (fmap f . fmap g) x</code>
</li></ul>
@ -679,7 +743,7 @@ fmap head (Cons 'c' [1,2,3])== Cons 'c' 1
<p>Haskell Functors are:</p>
<ul><li><em>endofunctors</em> ; \(F:\C→\C\) here \(\C = \Hask\),
</li><li>a couple <b>(Object,Morphism)</b> of Hask.
</li><li>a couple <b>(Object,Morphism)</b> in \(\Hask\).
</li></ul>
</section>
<section class="slide">
@ -776,7 +840,7 @@ Haskell types is fractal:</p>
</section>
<section class="slide">
<h2 id="monads-are-just-monoids-24">Monads are just Monoids (2/4)</h2>
<p>A Monad is a triplet \((M,μ,η)\) s.t.</p>
<p>A Monad is a triplet \((M,,η)\) s.t.</p>
<ul>
<li>\(M\) an <span class="yellow">Endofunctor</span></li>
<li>\(⊙:M×M→M\) a nat. trans. (× is functor composition)</li>
@ -831,10 +895,10 @@ join (η Nothing) = Nothing = Nothing</code></pre>
g=\x->[x+1] ⇒ g 1 = [2] ⇒ (g.g) 1 = ERROR [2]+1
h=\x->[x+1,x*10] ⇒ h 1 = [2,10] ⇒ (h.h) 1 = ERROR [2,10]+1</code></pre>
<p>How to fix that? <code>x &gt;&gt;= f = join (fmap f x)</code> (<code>join</code> is ⊙)</p>
<pre class="haskell"><code>f=\x->[x] ⇒ f 1 = [1] ⇒ f 1 >>= f = [1]
g=\x->[x+1] ⇒ g 1 = [2] ⇒ g 1 >>= g = [3]
h=\x->[x+1,x*10] ⇒ h 1 = [2,10] ⇒ h 1 >>= h = [3,20,11,100]</code></pre>
<p>How to fix that? <code>f =&lt;&lt; x = join (fmap f x)</code> <span class="small">(<code>join</code> is ⊙, <code>(&gt;&gt;=)=flip (=&lt;&lt;)</code>)</span></p>
<pre class="haskell"><code>f=\x->[x] ⇒ f 1 = [1] ⇒ f =<< f 1 = [1]
g=\x->[x+1] ⇒ g 1 = [2] ⇒ g =<< g 1 = [3]
h=\x->[x+1,x*10] ⇒ h 1 = [2,10] ⇒ h =<< h 1 = [3,20,11,100]</code></pre>
</section>

View file

@ -2,6 +2,7 @@
<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>About this presentation</li>
<li>Math <span class="and">&amp;</span> Abstraction</li>
<li>Programming <span class="and">&amp;</span> Abstraction</li>
<li>Categories <span class="and">&amp;</span> Abstraction</li>

View file

@ -0,0 +1,6 @@
<h2 id="about-this-presentation">About this presentation</h2>
<ul>
<li>A lot of slides, but short with pictures,</li>
<li>General Ideas → Definitions → Examples using Haskell,</li>
<li>About very fundamental Math, but I'll try not to digress.</li>
</ul>

View file

@ -0,0 +1,6 @@
About this presentation
-----------------------
- A lot of slides, but short with pictures,
- General Ideas → Definitions → Examples using Haskell,
- About very fundamental Math, but I'll try not to digress.

View file

@ -0,0 +1,9 @@
<h2 id="category-theory-goal">Category Theory Goal?</h2>
<p>Many different approach about Category Theory:</p>
<ul>
<li><a href="http://math.ucr.edu/home/baez/rosetta.pdf">Homogeneous vocabulary and notations</a></li>
<li><a href="http://math.ucr.edu/home/baez/rosetta.pdf">Bridge between disciplines</a></li>
<li><a href="http://www.math.harvard.edu/~mazur/preprints/when_is_one.pdf">Better definition of equality</a></li>
<li><a href="www.math.harvard.edu/~mazur/preprints/when_is_one.pdf">Generalization by default</a></li>
<li>Better math foundations</li>
</ul>

View file

@ -0,0 +1,10 @@
Category Theory Goal?
---------------------
Many different approach about Category Theory:
- [Homogeneous vocabulary and notations](http://math.ucr.edu/home/baez/rosetta.pdf)
- [Bridge between disciplines](http://math.ucr.edu/home/baez/rosetta.pdf)
- [Better definition of equality](http://www.math.harvard.edu/~mazur/preprints/when_is_one.pdf)
- [Generalization by default](www.math.harvard.edu/~mazur/preprints/when_is_one.pdf)
- Better math foundations

View file

@ -0,0 +1,12 @@
<h2 id="what-can-category-theory-do-for-us">What can Category Theory do for us?</h2>
<ul>
<li>Ability to see problem differently</li>
<li>Ability to abstract at the right level</li>
<li>Reduce bugs by separating concepts</li>
</ul>
<p>What did they already done?</p>
<ul>
<li>Functors, Applicative Functor, Monads, Arrows</li>
<li>Generalize <code>fold</code></li>
<li>...</li>
</ul>

View file

@ -0,0 +1,12 @@
What can Category Theory do for us?
-----------------------------------
- Ability to see problem differently
- Ability to abstract at the right level
- Reduce bugs by separating concepts
What did they already done?
- Functors, Applicative Functor, Monads, Arrows
- Generalize `fold`
- ...

View file

@ -1,5 +1,5 @@
<h2>Abstraction</h2>
<p>A common concept you see often in multiple instances.</p>
<p>A common concept you see in multiple instances.</p>
<div>
<p>Numbers: 1,2,3,... <em class="small">3400 BC, real numbers 760 BC</em></p>
<figure class="left">

View file

@ -33,4 +33,6 @@
<tr><td></td><td>Modules,Vector Spaces, Monoids, ...</td><td></td></tr>
</table>
<p><span class="and" style="visibility:hidden">&amp;</span> More <strong>general</strong>: more things are <span class="yellow">categories</span>.<br/>
<span class="and">&amp;</span> More <strong>abstract</strong>: generalization for free; replace = by <span class="yellow"></span>.</p>
<span class="and">&amp;</span> More <strong>abstract</strong>: generalization for free; replace = by <span class="yellow"></span>.<br/>
<span class="and">&amp;</span> Homogeneous <strong>vocabulary</strong>.
</p>

View file

@ -1,16 +0,0 @@
<h2>Polymorphism: <code>mappend (<>)</code></h2>
<pre class="haskell"><code>"abc" <> "def" = "abcdef" -- String
("ab","xy") <> ("AB","XY") = ("abAB","xyXY") -- (String,String)
3 <> 4 ⇒ ERROR which law? + or * -- Int
-- Use a type to remove ambiguity
type Sum = Sum {getSum :: a} -- Just a named box
-- Monoid (N,+)
(<>+) = getSum (Sum x <> Sum y)
3 <>+ 4 = 7
-- Monoid (N,*)
(<>*) = getProduct (Product x <> Product y)
3 <>* 4 = 12</code></pre>

View file

@ -0,0 +1,19 @@
<h2>Polymorphism: <code>mappend (<>)</code></h2>
<pre class="small haskell"><code> "abcdef" <span class="red"><></span> "ABCDEF" = "abcdefABCDEF" -- String
("ab","xy") <span class="red"><></span> ("AB","XY") = ("abAB","xyXY") -- (String,String)
3 <span class="red"><></span> 4 ⇒ ERROR which law? + or * -- Int
-- Use a type to remove ambiguity
type Sum = Sum {getSum :: a} -- Just a named box
-- Monoid (Int,+,0)
(<>+) = getSum (Sum x <span class="red"><></span> Sum y)
3 <>+ 4 = 7
-- Monoid (Int,*,0)
type Product = Product {getProduct :: a} -- Just a named box
(<>*) = getProduct (Product x <span class="red"><></span> Product y)
3 <>* 4 = 12</code></pre>
<p>Note: with Monoids (M,⊙,e); <code>foldl ⊙ e ms = foldr ⊙ e ms</code></p>

View file

@ -1,9 +1,9 @@
<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="small haskell"><code>data Maybe a = Just a | Nothing</code></pre>
<pre class="haskell"><code>-- Maybe Int >>= Int -> Maybe (Int -> Int) >>= (Int -> Int) -> Maybe Int
<pre class="small haskell"><code>-- Maybe Int >>= Int -> Maybe (Int -> Int) >>= (Int -> Int) -> Maybe Int
(Just 2) <span class="red">&gt;&gt;=</span> \x -> (Just (\z->z*z)) <span class="red">&gt;&gt;=</span> \f -> Just (f x) = Just 4
Nothing <span class="red">&gt;&gt;=</span> \x -> (Just (\z->z*z)) <span class="red">&gt;&gt;=</span> \f -> Just (f x) = Nothing

View file

@ -1,3 +1,3 @@
<h2>Category laws: neutral element</h2>
<p>for all \(X\), there is an \(\id_X\), s.t. for all \(f:A→B\):</p>
<p>for each object \(X\), there is an \(\id_X\), s.t. for all \(f:A→B\):</p>
<img src="categories/img/mp/identity.png" alt="identity"/>

View file

@ -1,4 +1,5 @@
<h2>Can this be a category?</h2>
<p>\(\ob{\C},\hom{\C}\) fixed, is there a valid ∘?</p>
<figure class="left">
<img src="categories/img/mp/cat-example1.png" alt="Category example 1"/>
<figcaption class="slide">

View file

@ -5,7 +5,6 @@
<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>\( \Hask\): (Haskell types, functions, <code>(.)</code> )</li>
<li>...</li>
</ul>

View file

@ -2,6 +2,6 @@
<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>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>, ...

View file

@ -1,13 +0,0 @@
<h2>Haskell Functor vs \(\Hask\) Functor</h2>
<p>Functor for Haskell language is a type <code>F :: * -> *</code> which belong to the type class <code>Functor</code></p>
<p>It must implement <code>fmap :: (a -> b) -> (F a -> F b)</code>.
<p><code>F</code>: \(\ob{\Hask}→\ob{\Hask}\) and <code>fmap</code>: \(\hom{\Hask}→\hom{\Hask}\)
<p>The couple <code>(F,fmap)</code> is then a real functor in the categorical sense for \(\Hask\) if</p>
<p>for any <code>x :: F a</code>:</p>
<ul><li><code>fmap id x = x</code>
</li><li><code>fmap (f.g) x= (fmap f . fmap g) x</code>
</li></ul>

View file

@ -0,0 +1,9 @@
<h2 id="haskell-kinds">Haskell Kinds</h2>
<p>In Haskell some types can take type variable. Typically: <code>[a]</code>.</p>
<pre><code>data Tree a = Node a [Tree a]
data CTree a b = CNode a [b]</code></pre>
<p>Types have <em>kind</em>; The kind is to type what type is to function. Kind are the &quot;type&quot; for some types (so meta).</p>
<pre><code>Int, Char :: *
[], Maybe, Tree :: * -&gt; *
CTree :: * -&gt; * -&gt; *
[Int], Maybe Char, Tree [Int] :: *</code></pre>

View file

@ -0,0 +1,21 @@
Haskell Kinds
-------------
In Haskell some types can take type variable.
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 "type" for some types (so meta).
~~~
Int, Char :: *
[], Maybe, Tree :: * -> *
CTree :: * -> * -> *
[Int], Maybe Char, Tree [Int] :: *
~~~

View file

@ -0,0 +1,14 @@
<h2 id="haskell-types">Haskell Types</h2>
<p>We can make function that can work for <em>all</em> type parameter. Such function can only work with the <em>topology</em> induced by the type. We know such function won't work <em>on</em> the elements.</p>
<p>Sometimes, the type determine a lot about the function:</p>
<pre class="haskell"><code>fst :: (a,b) -> a -- Only one choice
snd :: (a,b) -> b -- Only one choice
f :: a -> [a] -- Many choices
-- Possibilities: f x=[], or [x], or [x,x] or [x,...,x]
? :: [a] -> [a] -- Many choices
-- can only duplicate/remove/reorder elements
-- for example: the type of addOne isn't [a] -> [a]
addOne l = map (+1) l</code></pre>

View file

@ -0,0 +1,18 @@
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:
<pre class="haskell"><code>fst :: (a,b) -> a -- Only one choice
snd :: (a,b) -> b -- Only one choice
f :: a -> [a] -- Many choices
-- Possibilities: f x=[], or [x], or [x,x] or [x,...,x]
? :: [a] -> [a] -- Many choices
-- can only duplicate/remove/reorder elements
-- for example: the type of addOne isn't [a] -> [a]
addOne l = map (+1) l</code></pre>

View file

@ -0,0 +1,11 @@
<h2>Haskell Functor vs \(\Hask\) Functor</h2>
<p>Functor for Haskell language is a type <code>F :: * -> *</code> which belong to the type class <code>Functor</code>.<br/>
It must implement <code>fmap :: (a -> b) -> (F a -> F b)</code>.
<p><span style="visibility:hidden">&amp;</span> <code>F</code>: \(\ob{\Hask}→\ob{\Hask}\)<br/> &amp; <code>fmap</code>: \(\hom{\Hask}→\hom{\Hask}\)
<p>The couple <code>(F,fmap)</code> is a functor in the categorical sense for \(\Hask\) if for any <code>x :: F a</code>:</p>
<ul><li><code>fmap id x = x</code>
</li><li><code>fmap (f.g) x= (fmap f . fmap g) x</code>
</li></ul>

View file

@ -3,5 +3,5 @@
<p>Haskell Functors are:</p>
<ul><li><em>endofunctors</em> ; \(F:\C→\C\) here \(\C = \Hask\),
</li><li>a couple <b>(Object,Morphism)</b> of Hask.
</li><li>a couple <b>(Object,Morphism)</b> in \(\Hask\).
</li></ul>

View file

@ -3,4 +3,4 @@
<p>Haskell functor can be seen as boxes containing all Haskell types and functions.
Haskell types is fractal:</p>
<img src="categories/img/mp/hask-endofunctor-morphisms.png" alt="Haskell functor representation"/>
<img src="categories/img/mp/hask-endofunctor.png" alt="Haskell functor representation"/>

View file

@ -3,4 +3,4 @@
<p>Haskell functor can be seen as boxes containing all Haskell types and functions.
Haskell types is fractal:</p>
<img src="categories/img/mp/hask-endofunctor.png" alt="Haskell functor representation"/>
<img src="categories/img/mp/hask-endofunctor-morphisms.png" alt="Haskell functor representation"/>

View file

@ -1,5 +1,5 @@
<h2 id="monads-are-just-monoids-24">Monads are just Monoids (2/4)</h2>
<p>A Monad is a triplet \((M,μ,η)\) s.t.</p>
<p>A Monad is a triplet \((M,,η)\) s.t.</p>
<ul>
<li>\(M\) an <span class="yellow">Endofunctor</span></li>
<li>\(⊙:M×M→M\) a nat. trans. (× is functor composition)</li>

View file

@ -1,7 +1,7 @@
Monads are just Monoids (2/4)
-----------------------------
A Monad is a triplet \\((M,μ,η)\\) s.t.
A Monad is a triplet \\((M,,η)\\) s.t.
- \\(M\\) an <span class="yellow">Endofunctor</span>
- \\(⊙:M×M→M\\) a nat. trans. (× is functor composition)

View file

@ -4,9 +4,9 @@
g=\x->[x+1] ⇒ g 1 = [2] ⇒ (g.g) 1 = ERROR [2]+1
h=\x->[x+1,x*10] ⇒ h 1 = [2,10] ⇒ (h.h) 1 = ERROR [2,10]+1</code></pre>
<p>How to fix that? <code>x &gt;&gt;= f = join (fmap f x)</code> (<code>join</code> is ⊙)</p>
<pre class="haskell"><code>f=\x->[x] ⇒ f 1 = [1] ⇒ f 1 >>= f = [1]
g=\x->[x+1] ⇒ g 1 = [2] ⇒ g 1 >>= g = [3]
h=\x->[x+1,x*10] ⇒ h 1 = [2,10] ⇒ h 1 >>= h = [3,20,11,100]</code></pre>
<p>How to fix that? <code>f =&lt;&lt; x = join (fmap f x)</code> <span class="small">(<code>join</code> is ⊙, <code>(&gt;&gt;=)=flip (=&lt;&lt;)</code>)</span></p>
<pre class="haskell"><code>f=\x->[x] ⇒ f 1 = [1] ⇒ f =<< f 1 = [1]
g=\x->[x+1] ⇒ g 1 = [2] ⇒ g =<< g 1 = [3]
h=\x->[x+1,x*10] ⇒ h 1 = [2,10] ⇒ h =<< h 1 = [3,20,11,100]</code></pre>

View file

@ -7,8 +7,10 @@ Example with lists:
g=\x->[x+1] ⇒ g 1 = [2] ⇒ (g.g) 1 = ERROR [2]+1
h=\x->[x+1,x*10] ⇒ h 1 = [2,10] ⇒ (h.h) 1 = ERROR [2,10]+1</code></pre>
How to fix that? `x >>= f = join (fmap f x)` (`join` is ⊙)
How to fix that? `f =<< x = join (fmap f x)`
How to fix that? `f <=< g = `\x -> join (fmap f (g x))`
<span class="small">(`join` is ⊙, `(>>=)=flip (=<<)`)</span>
<pre class="haskell"><code>f=\x->[x] ⇒ f 1 = [1] ⇒ f 1 >>= f = [1]
g=\x->[x+1] ⇒ g 1 = [2] ⇒ g 1 >>= g = [3]
h=\x->[x+1,x*10] ⇒ h 1 = [2,10] ⇒ h 1 >>= h = [3,20,11,100]</code></pre>
<pre class="haskell"><code>f=\x->[x] ⇒ f 1 = [1] ⇒ f =<< f 1 = [1]
g=\x->[x+1] ⇒ g 1 = [2] ⇒ g =<< g 1 = [3]
h=\x->[x+1,x*10] ⇒ h 1 = [2,10] ⇒ h =<< h 1 = [3,20,11,100]</code></pre>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9 KiB

After

Width:  |  Height:  |  Size: 9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -40,8 +40,8 @@ drawEdge(intlist,intlist,"\mathtt{tail}");
drawEdge(fintlist,fintlist,"\scriptstyle\mathtt{fmap\ tail}");
drawoptions(withcolor blue withpen pencircle scaled 1);
drawEdge(intlist,int,"\mathtt{head}");
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ head}");
drawEdge(intlist,int,"\mathtt{length}");
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ length}");
drawoptions(withcolor base1);
drawState(int,"\mathtt{Int}");
@ -67,21 +67,21 @@ label.top(btex $\mathtt{F\ F}$ etex, blockLabelPosition(b)) scaled .5 shifted ff
draw b scaled .25 shifted ff;
label.top(btex $\mathtt{F\ F\ F}$ etex, blockLabelPosition(b)) scaled .25 shifted ff;
pair psqrt,pid,phead,podd,peven,ptail;
pair pfsqrt,pfid,pfhead,pfodd,pfeven,pftail;
pair psqrt,pid,plength,podd,peven,ptail;
pair pfsqrt,pfid,pflength,pfodd,pfeven,pftail;
psqrt := midpoint(loopPoint(int,int shifted (0,1.6u)));
pid := midpoint(edge(int,int));
podd := midpoint(edgeAngle(int,bool,-30));
peven := midpoint(edgeAngle(int,bool,30));
ptail := midpoint(edge(intlist,intlist));
phead := midpoint(edge(intlist,int));
plength := midpoint(edge(intlist,int));
pfsqrt := midpoint(loopPoint(fint,fint shifted (0,1.9u)));
pfid := midpoint(edge(fint,fint));
pfodd := midpoint(edgeAngle(fint,fbool,-30));
pfeven := midpoint(edgeAngle(fint,fbool,30));
pftail := midpoint(edge(fintlist,fintlist));
pfhead := midpoint(edge(fintlist,fint));
pflength := midpoint(edge(fintlist,fint));
nodespace := 6bp;
drawoptions(withcolor yellow withpen pencircle scaled 1);
@ -91,7 +91,7 @@ drawoptions(withcolor green withpen pencircle scaled 1);
drawarrow edgeAngle(pid,pfid,20) dashed evenly;
drawoptions(withcolor blue withpen pencircle scaled 1);
drawarrow edgeAngle(phead,pfhead,-20) dashed evenly;
drawarrow edgeAngle(plength,pflength,-20) dashed evenly;
drawoptions(withcolor red withpen pencircle scaled 1);
drawarrow edgeAngle(podd,pfodd,0) dashed evenly;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

After

Width:  |  Height:  |  Size: 185 KiB

View file

@ -14,7 +14,7 @@ drawEdge(int,int,"\mathtt{id}");
drawEdgeAngle(int,bool,"\mathtt{odd}",-30);
drawEdgeAngle(int,bool,"\mathtt{even}",30);
drawEdge(intlist,intlist,"\mathtt{tail}");
drawEdge(intlist,int,"\mathtt{head}");
drawEdge(intlist,int,"\mathtt{length}");
pair decal;
pair fint,fbool,ffunc,fintlist,flist;
@ -30,7 +30,7 @@ drawEdge(fint,fint,"\scriptstyle\mathtt{fmap\ id}");
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ odd}",-30);
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ even}",30);
drawEdge(fintlist,fintlist,"\scriptstyle\mathtt{fmap\ tail}");
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ head}");
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ length}");
drawblock(fint,fbool,"\mathtt{F}");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 182 KiB

After

Width:  |  Height:  |  Size: 184 KiB

View file

@ -14,7 +14,7 @@ drawEdge(int,int,"\mathtt{id}");
drawEdgeAngle(int,bool,"\mathtt{odd}",-30);
drawEdgeAngle(int,bool,"\mathtt{even}",30);
drawEdge(intlist,intlist,"\mathtt{tail}");
drawEdge(intlist,int,"\mathtt{head}");
drawEdge(intlist,int,"\mathtt{length}");
pair decal;
pair fint,fbool,ffunc,fintlist,flist;
@ -31,7 +31,7 @@ drawEdge(fint,fint,"\scriptstyle\mathtt{fmap\ id}");
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ odd}",-30);
drawEdgeAngle(fint,fbool,"\scriptstyle\mathtt{fmap\ even}",30);
drawEdge(fintlist,fintlist,"\scriptstyle\mathtt{fmap\ tail}");
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ head}");
drawEdge(fintlist,fint,"\scriptstyle\mathtt{fmap\ length}");
drawblock(fint,fbool,"\mathtt{F}");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 73 KiB

View file

@ -19,4 +19,4 @@ drawEdge(int,int,"\mathtt{id}");
drawEdgeAngle(int,bool,"\mathtt{odd}",-30);
drawEdgeAngle(int,bool,"\mathtt{even}",30);
drawEdge(intlist,intlist,"\mathtt{tail}");
drawEdge(intlist,int,"\mathtt{head}");
drawEdge(intlist,int,"\mathtt{length}");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

@ -14,7 +14,7 @@ for rep in ??_*(/); do
cd $rep
i=10
for fic in *.html; do
title=$( <$fic grep h2 | sed 's/<[^>]*>//g;s/&[^;]*;//g;s/[^a-zA-Z]/_/g;s/__*/_/g;s/^_//;s/_$//;')
title=$( <$fic grep h2 | sed 's/<[^>]*>//g;s/&[^;]*;//g;s/[^a-zA-Z0-9]/_/g;s/__*/_/g;s/^_//;s/_$//;')
if ((i<100)); then
num="0$i"
else