initial commit

This commit is contained in:
Yann Esposito 2012-10-09 16:42:51 +02:00
commit d2124c1379
5 changed files with 165 additions and 0 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
*.o
*.hi
*~
Mandelbulb
hglmandel
02_Edges/HGLMandelEdge

68
00_Introduction.lhs Normal file
View file

@ -0,0 +1,68 @@
## Introduction
My last two post where about Haskell and how to do something useful with it.
Now, it is time to talk about Categories.
How this notion could help you and how it is easy to use with Haskell.
- What are categories?
- How to use them?
First, a realisation.
Programming paradigm. When you program, you resolve problems.
There are a lot of different means to resolve a problem.
Some general school of thought exists.
In programming, most people use the imperative paradigm.
You use some memory and update it.
More precisely, you destroy part of information by setting variables to new values.
Hidden somewhere, there is the model of the Turing machine.
Of course, it is more complex with modern architecture, but the paradigm is the same.
You have an infinite number of cell and you can write things on them.
But you must erase them.
Another paradigm, is the functional paradigm.
This time, you don't write on cells, but instead you have a flow of data.
And you transform the flows in another flows... Mostly it looks like pipes.
I am a bit restrictive here. But generally this is how functional programming is perceived.
The main theory behind this paradigm is the Set theory.
You have a set and you go from one set to another set by using a function.
But using I believe there is another paradigm arising from Category theory.
And from what I saw up until there.
Category theory is both more general and powerful to help solve problems.
First, you must realize there are categories everywhere.
With the category theory you can find relationships between quantum physics,
topology, logic (both predicate and first order), programming.
Most of the time, the object your are programming with will form a category.
This is the promise from the Category Theory.
Another even better paradigm.
A paradigm with gates between many different domains.
## Get some intuition
We write down the definition first.
And will discuss about some categories.
> **Definition**:
>
> A category \\(C\\) consist of:
>
> - A collection of _objects_ \\(ob(C)\\)
> - For every pair of objects \\((A,B)\\) a set \\(hom(A,B)\\)
> of _morphisms_ \\(f:A→B\\) (Another notation for \\(f\in hom(A,B)\\))
> - A composition operator \\(∘\\)
> which associate to each couple \\(g:A→B\\), \\(f:B→C\\) another morphism \\(f∘g:A→C\\).
>
> With the following properties
>
> - for each object \\(x\\) there is an identity morphism
> \\(id_x:x→x\\)
> s.t. for any morphism \\(f:A->B\\),
> \\(id_A∘f = f = f∘id_B\\)
> - for all triplet of morphisms \\(h:A->B\\), \\(g:B->C\\) and \\(f:C->D\\)
> \\( (f∘g)∘h = f∘(g∘h) \\)

21
config.ymd Executable file
View file

@ -0,0 +1,21 @@
-----
isHidden: false
menupriority: 1
kind: article
created_at: 2012-10-01T19:16:43+02:00
en: title: Categeory Theory Programming
fr: title: Programmation en Théorie des Catégories
author_name: Yann Esposito
author_uri: yannesposito.com
tags:
- Haskell
- programming
- functional
- category theory
-----
begindiv(intro)
en: %tldr How to program using category theory.
fr: %tlal Comment programmer en utilisant la théorie des catégories.

32
create_ymd.sh Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env zsh
function writeTOC() {
cat <<END
> <center><hr style="width:30%;float:left;border-color:#CCCCD0;margin-top:1em"/><span class="sc"><b>Table of Content</b></span><hr style="width:30%;float:right;border-color:#CCCCD0;margin-top:1em"/></center>
>
> * This will be replaced by the ToC
> {:toc}
>
END
}
cat config.ymd
writeTOC
cat <<END
enddiv
END
for fic in **/*.lhs(.N); do
contains_haskell=$(( $( egrep '^>' $fic | wc -l) > 0 ))
((contains_haskell)) && \
print -- "\n<hr/><a href=\"code/$fic\" class=\"cut\">Download the source code of this section → ${fic:h}/<strong>${fic:t}</strong></a>\n"
cat $fic
((contains_haskell)) && \
print -- "\n<a href=\"code/$fic\" class=\"cut\">Download the source code of this section → ${fic:h}/<strong>${fic:t}</strong> </a>\n"
done | perl -pe 'BEGIN{$/="";} s#((^>.*\n)+)#<div class="codehighlight">\n<code class="haskell">\n$1</code>\n</div>\n#mg' | perl -pe 's#^> ?##' | perl -pe 's/^ #/#/'

38
prev Executable file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env zsh
webroot="$HOME/Sites/webroot"
print -- "Search script"
while [[ ! -x ./create_ymd.sh ]]; do
[[ $PWD = "/" ]] && {
print -- "Error: can't find create_ymd.sh" >&2
exit 1
}
cd ..
done
print -- "Create article"
./create_ymd.sh > $webroot/latest.ymd
print -- "Copy source codes"
ycp() {
local precedent=""
for e in $*;do
[[ $precedent != "" ]] && print -- "\t$precedent"
precedent=$e
done
cp $*
}
latestArticleDir=$(ls -l $webroot/latest.ymd | perl -pi -e 's#.*/##; s#.md$##')
for langue in en fr; do
dst="$webroot/output/Scratch/$langue/blog/$latestArticleDir/code"
[[ ! -d $dst ]] && mkdir -p $dst
ycp *.lhs(N) $dst
for dir in ??_*(N/); do
[[ ! -d $dst/$dir ]] && mkdir $dst/$dir
ycp $dir/*.{lhs,hs}(.N) $dst/$dir
done
done
print -- "\nRecompile"
cd $webroot
./tasks/recompile