<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>Alessandro Vermeulen</title>
	<atom:link href="http://alessandrovermeulen.me/feed/" rel="self" type="application/rss+xml" />
	<link>http://alessandrovermeulen.me</link>
	<description>Alessandro Vermeulen&#039;s blog about languages, programming, Computer Science and the Web.</description>
	<lastBuildDate>Wed, 28 Apr 2010 12:28:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Moving to Doctrine 1.2.x</title>
		<link>http://alessandrovermeulen.me/2010/04/28/moving-to-doctrine-1.2.x/</link>
		<comments>http://alessandrovermeulen.me/2010/04/28/moving-to-doctrine-1.2.x/#comments</comments>
		<pubDate>Wed, 28 Apr 2010 12:28:05 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=252</guid>
		<description><![CDATA[Here are some updates on my previous article. Doctrine meets Codeigniter. Do not forget to add the following autoload directive to your hooks/doctrine.php and the doctrine.php cli: spl_autoload_register(array('Doctrine', 'modelsAutoload'));]]></description>
			<content:encoded><![CDATA[<p>Here are some updates on my previous article. <a href="http://alessandrovermeulen.me/2009/04/17/doctrine-meets-codeigniter/">Doctrine meets Codeigniter</a>.</p>
<p>Do not forget to add the following autoload directive to your hooks/doctrine.php and the doctrine.php cli:</p>
<pre class="brush: php;">spl_autoload_register(array('Doctrine', 'modelsAutoload'));</pre>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2010/04/28/moving-to-doctrine-1.2.x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debian Lenny and the Haskell Platform</title>
		<link>http://alessandrovermeulen.me/2010/02/10/debian-lenny-and-the-haskell-platform/</link>
		<comments>http://alessandrovermeulen.me/2010/02/10/debian-lenny-and-the-haskell-platform/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 23:36:28 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Haskell Platform]]></category>
		<category><![CDATA[Lenny]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=241</guid>
		<description><![CDATA[Currently there is no package for the Haskell-Platform in Debian stable. However, the source of this platform and GHC is available for download at ghc and platform. However, there are some issues to solve when installing the platform from source. Mainly you'll be missing several packages. The following commands worked at my own Debian machine. [...]]]></description>
			<content:encoded><![CDATA[<p>Currently there is no package for the Haskell-Platform in Debian stable. However, the source of this platform and GHC is available for download at <a href="http://www.haskell.org/ghc/">ghc</a> and <a href="http://www.haskell.org/platform">platform</a>.</p>
<p>However, there are some issues to solve when installing the platform from source. Mainly you'll be missing several packages. The following commands worked at my own Debian machine. If you find out that's something is missing that was apparently already installed on my machine, don't hesitate to leave a comment.</p>
<p>The following commands are all executed as <em>root</em>.<br />
First we need to download the sources, I'm using the x86 sources, but feel free to use the x64 version:</p>
<pre class="brush: bash;">
cd /tmp
wget http://www.haskell.org/ghc/dist/6.10.4/ghc-6.10.4-i386-unknown-linux-n.tar.bz2
wget http://hackage.haskell.org/platform/2009.2.0.2/haskell-platform-2009.2.0.2.tar.gz
</pre>
<p>Now we need to extract these sources:</p>
<pre class="brush: bash;">
tar xvf ghc-6.10.4-i386-unknown-linux-n.tar.bz2
tar xvzf haskell-platform-2009.2.0.2.tar.gz
</pre>
<p>Before we do any other stuff, let's ensure that we have all the packages and libraries we need before continuing.</p>
<pre class="brush: bash;">
apt-get install build-essential libghc6-opengl-dev libghc6-glut-dev libeditline-dev libedit2 libedit-dev
</pre>
<p>Also make sure that you apply this patch to the platform, the bug has been around for some time now but hasn't been fixed apparently, it can be found at <a href="http://trac.haskell.org/haskell-platform/ticket/84">bug #84</a>:</p>
<pre class="brush: bash;">
patch -p0 haskell-platform-2009.2.0.2/scripts/install.sh
Index: haskell-platform-2009.2.0.2/scripts/install.sh
===================================================================
--- haskell-platform-2009.2.0.2.orig/scripts/install.sh
+++ haskell-platform-2009.2.0.2/scripts/install.sh
@@ -34,13 +34,23 @@ install_pkg () {
   fi
 }
+# Is this exact version of the package already installed?
+is_pkg_installed () {
+  PKG_VER=$1
+  grep &quot; ${PKG_VER} &quot; installed.packages &gt; /dev/null 2&gt;&amp;1
+}
+
 # Actually do something!
 cd packages
 for pkg in `cat platform.packages`; do
-  cd &quot;${pkg}&quot; || die &quot;The directory for the component ${PKG} is missing&quot;
-  echo &quot;Installing ${pkg}...&quot;
-  install_pkg ${pkg}
-  cd ..
+  if is_pkg_installed &quot;${pkg}&quot;; then
+    echo &quot;Platform package ${pkg} is already installed. Skipping...&quot;
+  else
+    cd &quot;${pkg}&quot; || die &quot;The directory for the component ${PKG} is missing&quot;
+    echo &quot;Installing ${pkg}...&quot;
+    install_pkg ${pkg}
+    cd ..
+  fi
 done
 echo
</pre>
<p>Now go to the ghc dir and build it.</p>
<pre class="brush: bash;">
cd ghc-6.10.4
./configure
make install
</pre>
<p>And if all of this goes well you can now go to the haskell-platform dir and install it:</p>
<pre class="brush: bash;">
cd ../haskell-platform-2009.2.0.2/
./configure
make
make install
</pre>
<p>And done! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2010/02/10/debian-lenny-and-the-haskell-platform/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Datatypes and Folds: Part II</title>
		<link>http://alessandrovermeulen.me/2010/01/03/haskell-datatypes-and-folds-part-ii/</link>
		<comments>http://alessandrovermeulen.me/2010/01/03/haskell-datatypes-and-folds-part-ii/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 23:09:28 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Fold]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Type Algebra]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=218</guid>
		<description><![CDATA[Non-mutually recursive and Mutually recursive datatypes Welcome back. In this post we will look at creating type algebra's and folds for more complicated data types. In essence, this exercise will not be any more difficult than the previous ones, provided that you stick with the steps. Up in this part, are the non-mutually recursive datatypes [...]]]></description>
			<content:encoded><![CDATA[<h3>Non-mutually recursive and Mutually recursive datatypes</h3>
<p>Welcome back. In this post we will look at creating type algebra's and folds for more complicated data types. In essence, this exercise will not be any more difficult than the previous ones, provided that you stick with the steps. Up in this part, are the non-mutually recursive datatypes and mutually recursive datatypes.</p>
<p>First up, data structures that are recursive into other data structures. The folds for these data structures are no more complex than their `simpler' forms. In fact, you could treat them the same, but for clarity we will treat them as distinct. If you want to know more about the previous part, it might help your search if you look for the keyword <em>catamorphism</em>.</p>
<h4>Non-mutually recursive datastructures</h4>
<p>Look at the following data structure. It's <em>data constructors</em> refer both back to the data structure itself and to another data structure. The other data structure has no reference back to this structure. This kind of data structures are quite common.</p>
<pre class="brush: haskell;">
data MaybeTree a = Node (Maybe a) (MaybeTree a) (MaybeTree a)
                   | Leaf (Maybe a)
-- This one is already defined in the prelude
data Maybe a = Just a | Nothing
</pre>
<p>Recall that in our previous folds and algebras we choose to replace our self-recursive types with a free variable <code>r</code>. In this case we also have a reference to another data structure, namely <code>Maybe a</code>. We will denote this by using another free variable, lets say <code>m</code>.</p>
<pre class="brush: haskell;">
type MaybeTreeAlgebra a m r = (  ( m -&gt; r -&gt; r -&gt; r -- Node
                                 , m -&gt; r           -- Leaf
                                 )
                              ,  ( a -&gt; m           -- Just
                                 , m                -- Nothing
                                 )
                              )
</pre>
<p>Notice that we've split up the the functions for each data type in separate tuples. This is to make the algebra somewhat more readable. It has one disadvantage though which we'll see later on.</p>
<p>We obtained this algebra by methodically looking at the types of the constructor functions and replacing any recursive types by their free variable counterparts, <code>r</code> for <code>MaybeTree a</code> and <code>m</code> for <code>Maybe a</code>.</p>
<p>Now we are going to construct the fold function. We will be doing this in exactly the same way as we did with all previous folds.</p>
<ol>
<li>Determine which datatypes are used (previously there was only one); This step is very simple if you already have the algebra.</li>
<li>for each of these datatypes exhaustively define a fold function;</li>
<li>look at the result.</li>
</ol>
<p>Following these steps again gives us the fold on our datatype. Please convince yourself that this is the case by defining <code>foldMaybeTree</code> yourself. </p>
<p>If we do it exactly as described above it will provide us with the following fold. Notice that we gave meaningful names to every replacement function stating the datatype they are intended for. Except for the top level function which we called <code>f</code>. This is because writing out the whole name for that function everywhere would be to much of a hassle and if you use <code>f</code> for this way it will be quite clear in time.</p>
<pre class="brush: haskell;">
foldMaybeTree' :: MaybeTreeAlgebra a m r -&gt; MaybeTree a -&gt; r
foldMaybeTree' ((node, leaf), (just, nothing)) = f
  where f (Node x l r) = node (maybe x) (f l) (f r)
        f (Leaf x)     = leaf (maybe x)
        maybe (Just x)  = just x
        maybe (Nothing) = nothing
</pre>
<p>Notice that we are using a datatype here that is already defined in the prelude. It would be wise to check whether someone didn't already provide a fold function for our little datatype <code>Maybe a</code>. Because that's we essentially did, we inlined the fold for <code>Maybe a</code> inside our fold for <code>MaybeTree a</code>. Obviously this isn't a problem if you are sure that your datatype will stay `contained in' in your datatype. </p>
<p>So we see that it is prudent to check for already existing folds if we use already existing datatypes. And it turns out that there already is a fold for <code>Maybe a</code>, namely <code>maybe</code>.</p>
<pre class="brush: haskell;">
maybe :: b -&gt; (a -&gt; b) -&gt; Maybe a -&gt; b
maybe n _ Nothing  = n
maybe _ f (Just x) = f x
</pre>
<p>So lets refine our little procedure to determine the fold of a datatype:</p>
<ol>
<li>Determine which datatypes are used (previously there was only one); This step is very simple if you already have the algebra.</li>
<li>for each of these datatypes exhaustively define a fold function or check whether such a fold function already exists;</li>
<li>look at the result.</li>
</ol>
<p>If we now use this knowledge our fold function can be written as follows:</p>
<pre class="brush: haskell;">
foldMaybeTree :: MaybeTreeAlgebra a m r -&gt; MaybeTree a -&gt; r
foldMaybeTree ((node, leaf), (just, nothing)) = f
  where f (Node x l r) = node (fmaybe x) (f l) (f r)
        f (Leaf x)     = leaf (fmaybe x)
        fmaybe = maybe nothing just
</pre>
<p>We've seen how to use algebra's but we haven't seen a step by step procedure for creating one. So let's add that to our procedure for creating our own folds. In our order to create the algebras as we've seen them here, with tupled functions you can follow this procedure:</p>
<p>For each data constructor in your datatype: create a function that takes the same parameters as the constructor function and replace every occurrence of a reference to one of your datatypes with a unique type variable (two occurrences to the same type should get the same variable). These functions should be grouped in tuples by their datatype. Do not forget to name all the type variables in the left-hand side of the type definition.</p>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2010/01/03/haskell-datatypes-and-folds-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Doctrine: Unable to parse string: Unable to parse line 0 (</title>
		<link>http://alessandrovermeulen.me/2010/01/01/doctrine-unable-to-parse-string-unable-to-parse-line-0/</link>
		<comments>http://alessandrovermeulen.me/2010/01/01/doctrine-unable-to-parse-string-unable-to-parse-line-0/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 11:58:34 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[Doctrine]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=213</guid>
		<description><![CDATA[Normally this error would mean that you have some weird syntax error somewhere in your yml files. However, if you are sure everything is up to spec be sure to check whether there are any `hidden' files in the folder. Such files start with a dot and are also read and parsed by the command [...]]]></description>
			<content:encoded><![CDATA[<p>Normally this error would mean that you have some weird syntax error somewhere in your yml files. However, if you are sure everything is up to spec be sure to check whether there are any `hidden' files in the folder. Such files start with a dot and are also read and parsed by the command line generator. </p>
<p>This could potentially fail, in case you get the aforementioned error. Be sure to remove these files before proceeding. To check whether there are any, go to the directory and retrieve it's listing.</p>
<pre class="brush: bash;">
cd /some/path/to/your/yml/files
ls -lha
</pre>
<p>If you see any files starting with a dot and ending in .yml be sure to check them for any valuable content and throw them away.</p>
<p>Thanks to <a href="http://blog.rajatpandit.com/2009/08/23/doctrine_parser_exception-fail-some-error-message/">rajat pandit</a> for hinting to this solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2010/01/01/doctrine-unable-to-parse-string-unable-to-parse-line-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Haskell Datatypes and Folds: Part I</title>
		<link>http://alessandrovermeulen.me/2009/12/17/haskell-datatypes-and-folds/</link>
		<comments>http://alessandrovermeulen.me/2009/12/17/haskell-datatypes-and-folds/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 08:56:28 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Fold]]></category>
		<category><![CDATA[Haskell]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=146</guid>
		<description><![CDATA[Welcome to this little explanation on how to determine the fold of a Haskell datatype. First we'll look at how we define functions over lists, something everyone starting with Haskell should be sufficiently familiar with, after which we move on to the datatypes. You'll see different ways how to calculate the sum of a list, [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to this little explanation on how to determine the fold of a Haskell datatype. First we'll look at how we define functions over lists, something everyone starting with Haskell should be sufficiently familiar with, after which we move on to the datatypes. You'll see different ways how to calculate the sum of a list, how to fold over a list, what datatypes are and, how to fold over a datatype, specifically the <code>BinTree a</code> datatype. Most importantly, I hope you will grow to understand what a fold is, and why they are so important and useful when programming Haskell.</p>
<p>During our functional programming course at Utrecht University I noticed students having anxiety of datatypes and even more for folds. Not because they couldn't grasp the workings of a single example but more a lack of a view on the complete picture and lack of experience with the Haskell datatype way.</p>
<p>So, what are datatypes? Datatypes are a way of notating the abstract structure of your data. There are several datastructures known to man, such as lists and trees.</p>
<h3>Lists</h3>
<p>Lists in Haskell are used in several ways. Today we will look at how to calculate the sum of a list. Intuitively you calculate the sum of a list by adding its elements together. Starting with the first element and then continuing on to the rest. This is how we literally translate that thought into Haskell code:</p>
<pre class="brush: haskell;">
sum :: [Int] -&gt; Int
sum []     = 0
sum (x:xs) = x + sum xs
-- sum [1..4] = 10
</pre>
<p>Would we be calculating the product of the list, we'd do the same except we multiply instead of adding.</p>
<pre class="brush: haskell;">
product :: [Int] -&gt; Int
product []     = 1
product (x:xs) = x * product xs
-- product [1..4] = 24
</pre>
<p>Looking at these two examples we can see that we have two similarities. We always have recursion on the tail of the list and we do something with the head of the list and the result of the recursion. In the first example we add them together, and in product we multiply them. Another property of most functions over lists is that there is a base case for the empty list. We call this the <em>identity</em> of our function, sometimes also referred to as <em>unit</em>. The identity of addition is 0 and the identity of multiplication is 1.</p>
<p>Now we look at one of the folds over lists defined in the prelude, <code>foldr</code>. Make sure you know what each parameter stands for. <strong>Note:</strong> There are some downsides to this function, mostly that it will not work for large lists, you'll see more on this later.</p>
<pre class="brush: haskell;">
foldr :: (a -&gt; b -&gt; b) -&gt; b -&gt; [a] -&gt; b
foldr f z []     = z
foldr f z (x:xs) = f x (foldr f z xs)
-- The line above can also be written as:
-- foldr f z (x:xs) = x `f` (foldr f z xs)
</pre>
<p>Now, take a moment to let this function soak in and try to think of how you would define <code>sum</code> and <code>product</code> in terms of this <code>foldr</code>. Crucial at this point is to notice that we do not see any type hardcoded in the type of <code>foldr</code> It may be helpful to look at this fold, which is the identity function for lists:</p>
<pre class="brush: haskell;">
idList :: [a] -&gt; [a]
idList list = foldr (:) [] list
-- Recall: [1,2,3,4,5] == 1 : 2 : 3 : 4 : 5 : []
</pre>
<p>If we look at our sum function, the operator between each recursive call is <code>(+)</code> and our base case is 0. So that's what we are going to use for our sum in terms of foldr.</p>
<pre class="brush: haskell;">
sumList :: [Int] -&gt; Int
sumList list = foldr (+) 0 list
-- sumList [1..4] = 10
</pre>
<p>Thus far we only have lists of <code>Int</code> for our examples. However, for sake of usability we will now move on to lists of numeric elements. Because <code>(+)</code> is defined for all numbers. (If you wish to read more on this subject please look up classes and instances.) Notice how the type of sumList changes while it's definition remains unaltered.</p>
<pre class="brush: haskell;">
sumList :: Num a =&gt; [a] -&gt; a
sumList list = foldr (+) 0 list
</pre>
<p>Now that we have seen how we can determine the function and identity for our fold from our recursive function to a definition in terms of <code>foldr</code>. And most importantly, the foldr takes care of the recursive nature of the list for us and the only thing it asks us in return for that is an operator and an identity for your operation. So the fold can now be used to define several operations on lists.</p>
<p>I told you about a problem of <code>foldr</code>. Depending on the size of your list the above <code>sumList</code> may not work. Try the following on your machine:</p>
<pre class="brush: bash;">
$ ghci
Prelude&gt; let sumList = foldr (+) 0
Prelude&gt; sumList [1..1000000]
*** Exception: stack overflow
</pre>
<p>Now try:</p>
<pre class="brush: bash;">
$ ghci
Prelude&gt; let sumList = Data.List.foldl' (+) 0
Prelude&gt; sumList [1..1000000]
500000500000
</pre>
<p>For a complete overview and analysis on <code>foldr</code> and <code>foldl</code> please read  <a href="http://www.cs.nott.ac.uk/~gmh/fold.pdf">A tutorial on the universality and expressiveness of fold</a>, by Graham Hutton.</p>
<h3>Trees</h3>
<p>First, let's take a look at how data structures in Haskell can be defined. In short we have the <code>data</code> keyword, followed by zero or more <code>type variables</code>, a <code>=</code> and then a number of <code>data constructors</code> separated by a <code>|</code>.</p>
<p>Now that you have familiarized yourself with lists we can proceed to a slightly more complicated datastructure. The Tree. In this example we will use a simple binary tree. A binary tree can be denoted as follows:</p>
<pre class="brush: haskell; light: true;">data BinTree a = Node a (BinTree a) (BinTree a) | Leaf deriving (Show, Eq)</pre>
<p>In this case <code>BinTree</code> is the <em>type constructor</em> and <code>Node</code> and <code>Leaf</code> the data <em>data constructors</em>.</p>
<p>Remember that the goal of folds is to seperate the implementation of the recursion from the actual operation we want to execute on the datatype. So we have one function, the <em>fold</em>, that takes care of the recursion and several other functions that use this fold to specify certain semantics on the datatype. We are going to calculate the sum of all elements in this tree.</p>
<p>The above binary tree has elements in the nodes and nothing in the leaves. You can notice the recursive occurrence of `<code>BinTree a</code>' in the node. We see two constructors in this datatype, <code>Node</code> and <code>Leaf</code>. The Node constructor expects some value of type <code>a</code> and two subtrees of type <code>BinTree a</code>, and the <code>Leaf</code> constructor has no parameters. In Haskell:</p>
<pre class="brush: haskell;">
Node :: a -&gt; BinTree a -&gt; BinTree a -&gt; BinTree a
Leaf :: BinTree a
</pre>
<p>Notice that our list also has two constructors, namely the <code>(:)</code> constructor that adds an element and the constructor for the empty list, <code>[]</code>. Analogously we have the <code>Node</code> and <code>Leaf</code> constructors. If we were allowed to use the <code>(:)</code> and <code>[]</code> constructor in our own Haskell code, the datatype for a list would look like this:</p>
<pre class="brush: haskell; light: true;">data List a = (:) a (List a) | []</pre>
<p>Also, it is customary to keep the arguments for the functions in the same order as the constructors are defined in the datatype, and to name the identifiers containing the functions the same as the constructor function but in lowercase. Applying this we get:</p>
<pre class="brush: haskell;">
foldBinTree :: (a -&gt; BinTree a -&gt; BinTree a -&gt; BinTree a) -&gt; (BinTree a) -&gt; BinTree a -&gt; ??
foldBinTree node leaf = f
  where f (Node x left right) = node x (f left) (f right)
        f (Leaf)              = leaf
</pre>
<p>I left out the result type of this fold, try to find it yourself before continuing.</p>
<p>By following our code we can see that every case, the case for <code>Node</code> and the one for <code>Leaf</code>, result in a <code>BinTree a</code>. Consequently the complete result of the function is a <code>BinTree a</code></p>
<p>Now recall that we previously used a fold to calculate the sum of a list. With that fold we were not restricted to a list. Which is also clearly visible by looking at the type of <code>foldr</code> it contains only type variables. As we want to calculate sum of the elements in this tree, which is something of type <code>a</code> and not of type <code>BinTree a</code> we have to revise the type of our fold. Notice the recurrence of the datatype in it's declaration, <code>BinTree a</code>. We will replace all of these occurences in the types of our functions with a free type variable, say <code>r</code>:</p>
<pre class="brush: haskell;">
foldBinTree :: (a -&gt; r -&gt; r -&gt; r) -&gt; (r) -&gt; BinTree a -&gt; r
foldBinTree node leaf = f
  where f (Node x left right) = node x (f left) (f right)
        f (Leaf)              = leaf
</pre>
<p>Keep in mind that I used 'eta reduction' in the above code. This means that the last parameter (in this case the tree) isn't explicitly specified as it would appear at the very end of the parameter list and ath the very end of the definition. (<a href="http://www.haskell.org/haskellwiki/Eta_conversion">More on eta reduction</a>.) So, now let's do something with this fold. Suppose we have the following tree:</p>
<pre class="brush: haskell;">
bintree = Node 1
            (Node 2
              (Node 3 Leaf Leaf)
              (Node 3 Leaf Leaf)
            )
            (Node 2
              (Node 3 Leaf Leaf)
              (Node 3 Leaf Leaf)
            )
</pre>
<p>A visual representation:</p>
<pre>            1
          /  \
         2    2
        / \  / \
       3   3 3  3</pre>
<p>Now we can define several traversals over this tree. Let's calculate the sum of all values in the tree.</p>
<pre class="brush: haskell;">
sumBinTree :: Num a =&gt; BinTree a -&gt; a
sumBinTree = foldBinTree (\val res_left res_right -&gt; val + res_left + res_right)
                         0
</pre>
<h4>Algebras</h4>
<p>The type of our foldBinTree is now more compact. However, there will be datatypes that contain a larger sum of constructors that also may have more or less parameters than in our case. Defining the type of the fold on those datatypes as we have done before will inevitably lead to very clumsy type signatures. The idea is that we split up the section that denotes our functions into a separate type, namely the <em>algebra</em>.</p>
<p>So now we define an algebra for our datastructure. To do this we again look at each dataconstructor and determine it's type. The fold function takes care of the recursion, so applying this thought consequently gives us the following types and fold.</p>
<p>Keep in mind that we have to change the type of our fold, but not the definition of the fold itself!</p>
<pre class="brush: haskell;">
type BinTreeAlgebra a r = (a -&gt; r -&gt; r -&gt; r, -- Node
                           r -- Leaf
                          )
foldBinTree :: BinTreeAlgebra a r -&gt; BinTree a -&gt; r
</pre>
<p>Now we can again define a sum on all <code>Num a</code> trees. Notice that we went from to seperate parameters for the functions to one tuple with two elements.</p>
<pre class="brush: haskell;">
sumBinTree :: Num a =&gt; BinTree a -&gt; a
sumBinTree = foldBinTree (\val res_left res_right -&gt; val + res_left + res_right,
                          0)
</pre>
<pre class="brush: bash;">
$ ghci bintree.hs
*Main&gt; bintree
Node 1 (Node 2 (Node 3 Leaf Leaf) (Node 3 Leaf Leaf)) (Node 2 (Node 3 Leaf Leaf) (Node 3 Leaf Leaf))
*Main&gt; sumBinTree bintree
19
</pre>
<p>That's it for now. If you did not understand everything by the end of this article, don't panic. It will sink in eventually. Let this rest a day or two, and then read this article again and you'll understand folds better. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2009/12/17/haskell-datatypes-and-folds/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Setting up multiple applications with CodeIgniter</title>
		<link>http://alessandrovermeulen.me/2009/09/08/setting-up-multiple-applications-with-codeigniter/</link>
		<comments>http://alessandrovermeulen.me/2009/09/08/setting-up-multiple-applications-with-codeigniter/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 13:27:30 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=102</guid>
		<description><![CDATA[In addition to my previous post where I discussed the initial setup of your application with CI (CodeIgniter), I'll use this post to provide a method of setting up your environment for multiple applications. Now, in the previous post I was really sloppy about the locations of both the CodeIgniter system files and the application [...]]]></description>
			<content:encoded><![CDATA[<p>In addition to my previous post where I discussed the <a title="Setting up CodeIgniter – Basics" href="http://alessandrovermeulen.me/2009/05/22/setting-up-codeigniter/">initial setup of your application</a> with CI (CodeIgniter), I'll use this post to provide a method of setting up your environment for multiple applications.<br />
<span id="more-102"></span><br />
Now, in the previous post I was really sloppy about the locations of both the CodeIgniter system files and the application files. The same guidelines still apply, both the system folder and application folder should reside outside of the web document root to ensure safety.</p>
<p>First, we want to store our applications and CodeIgniter releases in separate folders. So for example store your CodeIgniter system folder in <em>/var/codeigniter/</em>. This could be done by doing a svn export (or checkout) with the following command-line statement:</p>
<pre class="brush: bash; light: true;">$ svn export http://dev.ellislab.com/svn/CodeIgniter/tags/v1.7.1/system/ /var/codeigniter/release-1.7.1</pre>
<p>Or you can download the <a href="http://www.codeigniter.com/download_files/CodeIgniter_1.7.1.zip">1.7.1 release</a> from the CodeIgniter website and copy the contents of the system folder to <em>/var/codeigniter/release-1.7.1</em>.</p>
<p>Now for each application you want to build you can do a export/checkout to our applications directory. As we are going to store our applications outside the document root you could pick <em>/var/applications/</em> as root directory for your CI applications. Now if you want to make a blog you just have to execute this command:</p>
<pre class="brush: bash; light: true;">$ svn export http://dev.ellislab.com/svn/CodeIgniter/tags/v1.7.1/system/application/ /var/applications/blog</pre>
<p> or
<pre class="brush: bash; light: true;">$ cp /var/codeigniter/release-1.7.1/application /var/applications/blog</pre>
<p>I prefer the SVN export as this will ensure that you always have a fresh copy. Otherwise, should you find yourself without an internet connection you can use the latter.</p>
<p>Now just as in the previous post, create the directory in the document root (whether you want to access it through a subfolder or directly through a sub-domain/domain is entirely up to you and is outside the scope of this post.)</p>
<pre class="brush: bash; light: true;">$ mkdir /var/www/blog</pre>
<p> Now get the index.php file from svn or from the zip file you might have downloaded earlier:</p>
<pre class="brush: bash; light: true;">svn export http://dev.ellislab.com/svn/CodeIgniter/tags/v1.7.1/index.php /var/applications/blog/</pre>
<p>The only thing left is to alter the index.php so the <em>$system_folder</em> and the <em>$application_folder</em> point in the right direction:</p>
<pre class="brush: php; gutter: false;"> //...
$system_folder = '/var/codeigniter/release-1.7.1';
//...
$application_folder = '/var/applications/blog';</pre>
<p>Now you can add your web stuff like CSS, JS  to your /var/www/blog. Of course this follows the same principle as creating the non-www and www directories mentioned in the previous post.</p>
<p>Now for each application you want to add, retake the above steps and replace 'blog' with something relevant. Good steaming!</p>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2009/09/08/setting-up-multiple-applications-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending the V in MVC &#8211; revisited</title>
		<link>http://alessandrovermeulen.me/2009/07/12/extending-the-v-in-mvc-revisited/</link>
		<comments>http://alessandrovermeulen.me/2009/07/12/extending-the-v-in-mvc-revisited/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 12:58:15 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[partial]]></category>
		<category><![CDATA[Partials]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rss]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=62</guid>
		<description><![CDATA[This post is an revised version of 'Extending the V in MVC on the web' of November 9, 2008. When I first started working with the MVC method it was with my own framework. After noticing that maintaining my own framework would be very time-comsuming I embarked on the search for a free, fast and [...]]]></description>
			<content:encoded><![CDATA[<p>This post is an revised version of 'Extending the V in MVC on the web' of November 9, 2008.</p>
<hr />
<p>When I first started working with the MVC method it was with my own framework. After noticing that maintaining my own framework would be very time-comsuming I embarked on the search for a free, fast and widely supported PHP web framework. The one I found that time was '<a href="http://www.codeigniter.com">CodeIgniter</a>'.</p>
<p>After working on different projects I noticed that most websites present the same data to the visitor in several different formats. Think of RSS/Atom for blog posts for use in an RSS reader together with the (x)html versions.</p>
<p>While essentially providing the same data to the visitor the programmer of the website has to put sizable amount of work to add little extra functionality in the form of an RSS feed. Repeating a lod of code for input validation, data retrieval from the database and creating extra routes into the application. As you can imagine this could grow into a tedious job.</p>
<p>I'll be describing techniques known and in use today, but reinvented each time again as a (new) developer starts working on an web application. Here we'll be giving them name and be describing them.</p>
<p><span id="more-62"></span></p>
<h3>Theory</h3>
<p>What are layouts? What are partials? The answers to these questions will be discussed in the following sections.</p>
<h4>Layouts</h4>
<p>What is a layout? We will be using the following definition of the word layout: "A layout is the representation of data in a specific format". So the layout of a page can be either, xhtml, RSS, PDF, PPT or any other data format.</p>
<p>Suppose you would find yourself in the situation where you need to write a blog. You could start with building the models that describe users, posts, comments and maybe even backtracks. Then you start writing the controllers and views and let someone else do the design for you. :)</p>
<p>So, the designer has made some nice designs and you are converting those to (x)html, CSS and images for use in your views. In the same time you write your controllers, one for every aspect of your blog. Consider the controller that shows a list of your most recent posts.</p>
<p>Blogs are essentially meant for publishing information, the messages the poster posts, to the world. People want to see a nice readable web page when they look at your blog. But it is hard to keep track of all the blogs one visits for new posts. That's why people invented the syndicates. And look now, here you are, having two URLs providing the same information, the latest posts, and the only difference is that the information is that they present the data in another format. So why should the URLs be different? - Other than the extension that denotes in which format the page should be presented? - Right, they shouldn't. Nor should you have to write any administrative code. The only code you should have to write is the code responsible for presenting the given data in a specific layout.</p>
<p>With just a small amount of initial trouble, which we'll see in the next chapter, it will save you a lot of time and administrative rut. Sounds good, doesn't it?</p>
<h4>Partials</h4>
<p>Another aspect of this article is 'partials'. Programming today is all about re-using code and rapid development and low-maintenance. OOP gives you the ability to re-use your previously written code you worked so hard on in a sensible matter. It also can help in reducing the draught of maintenance. The MVC paradigm is extending this and helps by further aiding rapid development.</p>
<p>In the aspect of re-using code, partials are very important. Where OOP , Models and Controllers can save you time by re-using program code, partials can help you save time by offering a new way to re-use your html (or any other layout) code. Thus not only decreasing the maintenance needed for your application but simultaneously increasing consistency throughout your application without causing you any headaches.</p>
<p>Where does the name 'partial' come from? The origins of this name are quite simple. A 'partial' is a small re-usable snippet of View code and is a View itself.</p>
<p>Partials can be used for many things. For example, the header on all your blog pages could be the same, apart from variables as titles and needed stylesheets and javascript includes. As we have learned during the age of the static webpages, maintaining this would be an hell of  a pain. So let's not do that anymore and let's use partials instead. Keep the code in one place and just use the partial if you need the header. Do no retype or copy any code.</p>
<p>Of course, headers and footers are not the only things that we can store in partials. The menu, the login form, the code for a blog post and the lot can be placed in partials. Actually almost anything that will be used more than once should be placed in a partial.</p>
<h3>An implementation in CodeIgniter</h3>
<p>This part shows one way to implement layouts and partials in CodeIgniter. We assume you have at least version 1.6.3 of CodeIgniter and that you have a fair idea of what we are going to do. Proceeding is completely at your own expense and I am not accountable for any issues that may rise do to these adjustments</p>
<h4>Adjustments</h4>
<h5>The Controller class</h5>
<p>The first thing we have to do is extending the main controller class provided by CodeIgniter. This enables us to do whatever we want without changing anything in the CodeIgniter code base. Place this function in the extending controller:</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #808080; font-style: italic;">/**
   * This function remaps the url and retrieves the desired extension from it. It then calls the appropiate controller method.
   *
   * @param string $aMethod
   */</span>
  <span style="color: #000000; font-weight: bold;">function</span> _remap<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$aMethod</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$lParams</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">uri</span>-&gt;<span style="color: #006600;">segment_array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <a href="http://www.php.net/array_shift"><span style="color: #000066;">array_shift</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lParams</span><span style="color: #66cc66;">&#41;</span>;array_shift<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lParams</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #0000ff;">$lMethod</span> = <span style="color: #0000ff;">$aMethod</span>;
    <span style="color: #0000ff;">$lLayout</span> = <span style="color: #ff0000;">'xhtml'</span>;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/strpos"><span style="color: #000066;">strpos</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lMethod</span>, <span style="color: #ff0000;">'.'</span><span style="color: #66cc66;">&#41;</span> !== <span style="color: #000000; font-weight: bold;">False</span><span style="color: #66cc66;">&#41;</span>
      <a href="http://www.php.net/list"><span style="color: #000066;">list</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lMethod</span>, <span style="color: #0000ff;">$lLayout</span><span style="color: #66cc66;">&#41;</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'.'</span>, <span style="color: #0000ff;">$lMethod</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">load</span>-&gt;<span style="color: #006600;">setLayout</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lLayout</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #0000ff;">$lMethod</span> = <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #000066;">empty</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lMethod</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #ff0000;">'index'</span> : <span style="color: #0000ff;">$lMethod</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/method_exists"><span style="color: #000066;">method_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>, <span style="color: #0000ff;">$lMethod</span><span style="color: #66cc66;">&#41;</span> &amp;&amp; !<a href="http://www.php.net/method_exists"><span style="color: #000066;">method_exists</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">__CLASS__</span>, <span style="color: #0000ff;">$lMethod</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <a href="http://www.php.net/call_user_func_array"><span style="color: #000066;">call_user_func_array</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this</span>, <span style="color: #0000ff;">$lMethod</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$lParams</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
      show_404<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lMethod</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<h5>The loader</h5>
<p>Now put these functions inside class extending the CI Loader class:</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #ff0000">protected <span style="color: #0000ff;">$layout</span>;
</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> partial<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$aPartial</span>, <span style="color: #0000ff;">$aData</span>=<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$aLayout</span>=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #0000ff;">$lLayout</span> = <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_null"><span style="color: #000066;">is_null</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$aLayout</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">layout</span> : <span style="color: #0000ff;">$aLayout</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #0000ff;">$lastItem</span> = <span style="color: #ff0000;">''</span>;
  <span style="color: #0000ff;">$parts</span>    = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/strpos"><span style="color: #000066;">strpos</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$aPartial</span>, <span style="color: #ff0000;">'/'</span><span style="color: #66cc66;">&#41;</span> !== <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$parts</span> = <a href="http://www.php.net/explode"><span style="color: #000066;">explode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/'</span>, <span style="color: #0000ff;">$aPartial</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
    <span style="color: #0000ff;">$lastItem</span> = <a href="http://www.php.net/array_pop"><span style="color: #000066;">array_pop</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$parts</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
  <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$lastItem</span> = <span style="color: #0000ff;">$aPartial</span>;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lastItem</span><span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#125;</span> !== <span style="color: #ff0000;">'_'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$lastItem</span> = <span style="color: #ff0000;">'_'</span>.<span style="color: #0000ff;">$lastItem</span>;
  <span style="color: #66cc66;">&#125;</span>
  <a href="http://www.php.net/array_push"><span style="color: #000066;">array_push</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$parts</span>, <span style="color: #0000ff;">$lastItem</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">view</span><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/implode"><span style="color: #000066;">implode</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/'</span>, <span style="color: #0000ff;">$parts</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$aData</span>, <span style="color: #0000ff;">$aLayout</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setLayout<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$aLayout</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_dir"><span style="color: #000066;">is_dir</span></a><span style="color: #66cc66;">&#40;</span>APPPATH.<span style="color: #ff0000;">'/views/'</span>.<span style="color: #0000ff;">$aLayout</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">layout</span> = <span style="color: #0000ff;">$aLayout</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * @param string $aView
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> view<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$aView</span>=<span style="color: #000000; font-weight: bold;">null</span>, <span style="color: #0000ff;">$aData</span>=<a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #0000ff;">$aLayout</span>=<span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_null"><span style="color: #000066;">is_null</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$aView</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #0000ff;">$aView</span> = <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">controllerName</span>.<span style="color: #ff0000;">'/'</span>.<span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">controllerFunction</span>;
&nbsp;
  <span style="color: #0000ff;">$lLayout</span> = <span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/is_null"><span style="color: #000066;">is_null</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$aLayout</span><span style="color: #66cc66;">&#41;</span> ? <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">layout</span> : <span style="color: #0000ff;">$aLayout</span><span style="color: #66cc66;">&#41;</span>;
  parent::<span style="color: #006600;">view</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$lLayout</span>.DIRECTORY_SEPARATOR.<span style="color: #0000ff;">$aView</span>, <span style="color: #0000ff;">$aData</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<h4>Usage</h4>
<h5>Views</h5>
<p>Now that we have extended the functionality of CodeIgniter with our own we can start to use layouts and partials. Consider the following url:</p>
<blockquote><p>http://someurl/blog/category/5</p></blockquote>
<p>It will give you a nice and cheesy overview formatted in xhtml. So let's take a look at the view file.</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">partial</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'header'</span>, <span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=<span style="color: #ff0000;">&quot;content&quot;</span>&gt;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$posts</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$post</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">partial</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'blog/shortsummary'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'post'</span> =&gt; <span style="color: #0000ff;">$post</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">partial</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'footer'</span>, <span style="color: #0000ff;">$data</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre>
<p>And the code for the short summary looks like this:</p>
<pre class="php">&nbsp;
&lt;div <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">&quot;blog post short&quot;</span>&gt;
&lt;h2&gt;&lt;?= <span style="color: #0000ff;">$post</span>-&gt;<span style="color: #006600;">title</span>; ?&gt;&lt;/h2&gt;
&nbsp;
  &lt;span <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">&quot;description&quot;</span>&gt;&lt;?= <span style="color: #0000ff;">$post</span>-&gt;<span style="color: #006600;">description</span>; ?&gt;&lt;/span&gt;
&lt;/div&gt;
&nbsp;</pre>
<p>Now consider this url:</p>
<blockquote><p>http://someurl/blog/category.rss/5</p></blockquote>
<p>This url would give you the overview of the posts in category 5. Just as with the url above. But this time the information will be formatted in RSS. Notice that the only thing we had to do was to change the url. Create these two files:</p>
<p><strong>APPPATH/views/rss/blog/summary.php</strong></p>
<pre class="php">&lt;channel&gt;
  &lt;items&gt;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$posts</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$post</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">partial</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'blog/shortsummary'</span>, <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'post'</span> =&gt; <span style="color: #0000ff;">$post</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;/items&gt;
&lt;/channel&gt;
&nbsp;</pre>
<p><strong>APPPATH/views/rss/blog/_shortsummary.php</strong></p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<a href="http://www.php.net/assert"><span style="color: #000066;">assert</span></a><span style="color: #66cc66;">&#40;</span>!<a href="http://www.php.net/is_null"><span style="color: #000066;">is_null</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$post</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;item&gt;
  &lt;title&gt;&lt;?=<span style="color: #0000ff;">$post</span>-&gt;<span style="color: #006600;">title</span>;?&gt;&lt;/title&gt;
  &lt;description&gt;&lt;?=<span style="color: #0000ff;">$post</span>-&gt;<span style="color: #006600;">description</span>;?&gt;&lt;/description&gt;
&lt;/item&gt;
&nbsp;</pre>
<p>Wow. Now we only had to write a few lines (15) for adding RSS feeds to our site. This is really all there is to it. Now go out there and have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2009/07/12/extending-the-v-in-mvc-revisited/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding COM(+) to your Delphi project</title>
		<link>http://alessandrovermeulen.me/2009/06/19/adding-com-to-your-delphi-project/</link>
		<comments>http://alessandrovermeulen.me/2009/06/19/adding-com-to-your-delphi-project/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 11:38:06 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[Notes]]></category>
		<category><![CDATA[COM+]]></category>
		<category><![CDATA[delphi 2009]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=57</guid>
		<description><![CDATA[If you're struggling with your IDE to add an COM(+) object to your project you should look in the .drp file of your project. If you include 'ComServ' in the uses list you should be fine. :) Now you're able to add an COM(+) object to your project using add->new.]]></description>
			<content:encoded><![CDATA[<p>If you're struggling with your IDE to add an COM(+) object to your project you should look in the .drp file of your project. If you include 'ComServ' in the uses list you should be fine. :) Now you're able to add an COM(+) object to your project using add->new.</p>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2009/06/19/adding-com-to-your-delphi-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up CodeIgniter &#8211; Basics</title>
		<link>http://alessandrovermeulen.me/2009/05/22/setting-up-codeigniter/</link>
		<comments>http://alessandrovermeulen.me/2009/05/22/setting-up-codeigniter/#comments</comments>
		<pubDate>Fri, 22 May 2009 19:21:21 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=35</guid>
		<description><![CDATA[In this post I'll show how to set up CodeIgniter in a way that your code and configuration (passwords!) are safe. It will involve moving the "system" and "application" outside the (public) document root. Seperating both `system' and `application' has obvious advantages for maintainance and for reusibility. Using a seperate `www' directory enables you to [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I'll show how to set up CodeIgniter in a way that your code and configuration (passwords!) are safe. It will involve moving the "<em>system</em>" and "<em>application</em>" outside the (public) document root.</p>
<p>Seperating both `<em>system</em>' and `<em>application</em>' has obvious advantages for maintainance and for reusibility. Using a seperate `<em>www</em>' directory enables you to publish all your application specific JS/CSS and other public files.</p>
<p><span id="more-35"></span></p>
<p>The first thing we need to do is to create an checkout of the latest CodeIgniter release (currently 1.7.1)<br />
<code>$ svn checkout http://dev.ellislab.com/svn/CodeIgniter/tags/v1.7.1/ somepathoutsidedocumentroot</code></p>
<p>now  move the application folder outside the system folder:<br />
<code><br />
$ cd  somepathoutsidedocumentroot<br />
$ mv system/application ./application</code></p>
<p>Now move the system and application folder to some folder outside of your public document root. Let's call this directory `<em>non-www</em>'. The documentroot directory will be called `<em>www</em>'.</p>
<p>In the root of your checkout you will find an <em>index.php</em>. Copy/move this file to <em>www</em>. Open it and look for the following lines:</p>
<pre class="php"><span style="color: #0000ff;">$system_folder</span> = <span style="color: #ff0000;">&quot;system&quot;</span>;
<span style="color: #0000ff;">$application_folder</span> = <span style="color: #ff0000;">&quot;application&quot;</span>;</pre>
<p>Change them to the following:</p>
<pre class="php"><span style="color: #0000ff;">$system_folder</span> = <span style="color: #ff0000;">&quot;../non-www/system&quot;</span>;
<span style="color: #0000ff;">$application</span>  = <span style="color: #ff0000;">&quot;../non-www/application&quot;</span>;</pre>
<p>Now you are up and running. Probably you want something like nice url's. For this you can use the following .htaccess<br />
<code><br />
RewriteEngine on<br />
RewriteRule ([^/]*)\/\?([^/?]*)$ $1/$2 [R]</code></p>
<p><code> </code></p>
<p><code>RewriteCond $1 !^(index\.php|test\.php|export\.php|robots\.txt|css|img|js|favicon\.ico|doc|data|user_guide|js)<br />
RewriteRule ^(.*)$ ./index.php/$1 [L]</code></p>
<p>Now, go and create some new shiny sites.</p>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2009/05/22/setting-up-codeigniter/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Doctrine meets CodeIgniter</title>
		<link>http://alessandrovermeulen.me/2009/04/17/doctrine-meets-codeigniter/</link>
		<comments>http://alessandrovermeulen.me/2009/04/17/doctrine-meets-codeigniter/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 20:40:49 +0000</pubDate>
		<dc:creator>Alessandro</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Doctrine]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[PHP]]></category>
		<guid isPermaLink="false">http://alessandrovermeulen.me/?p=28</guid>
		<description><![CDATA[Anyone who has made websites in the past has encountered it. The endless bugging typing of SQL queries, always doing the same over and over again. This struggle is lightened by the use of frameworks or even complete CM-Systems. However, SQL query writing is still often needed. To counter this (and other annoying pestering little [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone who has made websites in the past has encountered it. The endless bugging typing of SQL queries, always doing the same over and over again. This struggle is lightened by the use of frameworks or even complete CM-Systems. However, SQL query writing is still often needed.</p>
<p>To counter this (and other annoying pestering little details mongering), Object Relational Mappers were invented. <a href="http://www.doctrine-project.org" target="_blank">Doctrine</a> is a PHP implementation of the RoR ORM. And now it's quite easy to merge CodeIgniter and Doctrine into one package.</p>
<p>Just follow the <a href="http://alessandrovermeulen.me/wp-content/2009/09/README.html" target="_blank">readme</a> and continue your adventure.</p>
]]></content:encoded>
			<wfw:commentRss>http://alessandrovermeulen.me/2009/04/17/doctrine-meets-codeigniter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
