commit d2124c1379ff9c5ff324edb16355392213e21ee8 Author: Yann Esposito Date: Tue Oct 9 16:42:51 2012 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f5c163d --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.o +*.hi +*~ +Mandelbulb +hglmandel +02_Edges/HGLMandelEdge diff --git a/00_Introduction.lhs b/00_Introduction.lhs new file mode 100644 index 0000000..0561ea8 --- /dev/null +++ b/00_Introduction.lhs @@ -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) \\) + diff --git a/config.ymd b/config.ymd new file mode 100755 index 0000000..4e2249b --- /dev/null +++ b/config.ymd @@ -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. + diff --git a/create_ymd.sh b/create_ymd.sh new file mode 100755 index 0000000..641c908 --- /dev/null +++ b/create_ymd.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env zsh + +function writeTOC() { + +cat <

Table of Content
+> +> * This will be replaced by the ToC +> {:toc} +> +END + +} + +cat config.ymd + +writeTOC + +cat <' $fic | wc -l) > 0 )) + ((contains_haskell)) && \ + print -- "\n
Download the source code of this section → ${fic:h}/${fic:t}\n" + cat $fic + ((contains_haskell)) && \ + print -- "\nDownload the source code of this section → ${fic:h}/${fic:t} \n" +done | perl -pe 'BEGIN{$/="";} s#((^>.*\n)+)#
\n\n$1\n
\n#mg' | perl -pe 's#^> ?##' | perl -pe 's/^ #/#/' diff --git a/prev b/prev new file mode 100755 index 0000000..ea52c96 --- /dev/null +++ b/prev @@ -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