<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>..never odd or even..</title>
	<atom:link href="http://dorchard.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://dorchard.wordpress.com</link>
	<description>Thoughts on computer science, maths, languages.</description>
	<lastBuildDate>Sun, 23 Oct 2011 14:37:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dorchard.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s-ssl.wordpress.com/i/buttonw-com.png</url>
		<title>..never odd or even..</title>
		<link>https://dorchard.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://dorchard.wordpress.com/osd.xml" title="..never odd or even.." />
	<atom:link rel='hub' href='https://dorchard.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Subcategories &amp; &#8220;Exofunctors&#8221; in Haskell</title>
		<link>https://dorchard.wordpress.com/2011/10/18/subcategories-in-haskell-exofunctors/</link>
		<comments>https://dorchard.wordpress.com/2011/10/18/subcategories-in-haskell-exofunctors/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 00:46:12 +0000</pubDate>
		<dc:creator>dorchard</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[constraints]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[subcategories]]></category>

		<guid isPermaLink="false">http://dorchard.wordpress.com/?p=136</guid>
		<description><![CDATA[In my previous post I discussed the new constraint kinds extension to GHC, which provides a way to get type-indexed constraint families in GHC/Haskell. The extension provides some very useful expressivity. In this post I&#8217;m going to explain a possible use of the extension. In Haskell the Functor class is misleading named as it actually [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=136&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div align="justify">
<p> In my <a href="http://dorchard.wordpress.com/2011/09/22/constraint-kinds-in-haskell-finally-bringing-us-constraint-families/">previous post</a> I discussed the new <i>constraint kinds</i> extension to GHC, which provides a way to get type-indexed constraint families in GHC/Haskell. The extension provides some very useful expressivity. In this post I&#8217;m going to explain a possible use of the extension.</p>
<p> In Haskell the <tt>Functor</tt> class is misleading named as it actually captures the notion of an <i>endo</i>functor, not functors in general. This post shows a use of constraint kinds to define a type class of <i>exo</i>functors; that is, functors that are not necessarily endofunctors. I will explain what all of this means. </p>
<p>This example is just one from <a href="http://www.cl.cam.ac.uk/~dao29/drafts/subcategories-in-haskell-dorchard11.pdf">a draft note</a> explaining the use of constraint families, via the constraint kinds extension, for describing abstract structures from category theory that are parameterised by  <i>subcategories</i>, including non-endofunctors, <i>relative monads</i>, and <i>relative comonads</i>.</p>
<p>I will try to concisely describe any relevant concepts from category theory, through the lens of functional programming, although I&#8217;ll elide some details.</p>
<h3>The <b>Hask</b> category</h3>
<p>The starting point of the idea is that programs in Haskell can be understood as providing definitions within some category, which we will call <b>Hask</b>. Categories comprise a collection of <i>objects</i> and a collection of <i>morphisms</i> which are mappings between objects. Categories come equipped with identity morphisms for every object and an associative composition operation for morphisms (see <a href="http://en.wikipedia.org/wiki/Category_theory#Categories.2C_objects.2C_and_morphisms">Wikipedia</a> for a more complete, formal definition). For <b>Hask</b>, the objects are Haskell types, morphisms are functions in Haskell, identity morphisms are provided by the identity function, and composition is the usual function composition operation. For the purpose of this discussion we are not really concerned about the exact properties of <b>Hask</b>, just that Haskell acts as a kind of <i>internal language</i> for category theory, within some arbitrary category <b>Hask</b> (<a href="http://blog.sigfpe.com/2009/10/what-category-do-haskell-types-and.html">Dan Piponi provides some discussion on this topic</a>). </p>
<h3>Subcategories</h3>
<p>
Given some category <i>C</i>, a <a href="http://en.wikipedia.org/wiki/Subcategory"><i>subcategory</i></a> of <i>C</i> comprises a subcollection of the objects of <i>C</i> and a subcollection of the morphisms of <i>C</i> which map only between objects in the subcollection of this subcategory.</p>
<p>We can define for <b>Hask</b> a <i>singleton</i> subcategory for each type, which has just that one type as an object and functions from that type to itself as morphisms e.g. the <i>Int</i>-subcategory of <b>Hask</b> has one object, the <tt>Int</tt> type, and has functions of type <tt>Int &rarr; Int</tt> as morphisms. If this subcategory has <i>all</i> the morphisms <tt>Int &rarr; Int</tt> it is called a <i>full</i> subcategory. Is there a way to describe &#8220;larger&#8221; subcategories with more than just one object?</p>
<p>Via universal quantification we could define the trivial (<a href="http://en.wikipedia.org/wiki/Proper_subset#proper_subset">&#8220;non-proper&#8221;</a>) subcategory of <b>Hask</b> with objects of type <tt>a</tt> (implicitly universally quantified) and morphisms <tt>a -&gt; b</tt>, which is just <b>Hask</b> again. Is there a way to describe &#8220;smaller&#8221; subcategories with fewer than all the objects, but more than one object? Yes. For this we use type classes.</p>
<h3>Subcategories as type classes</h3>
<p>
The instances of a single parameter type class can be interpreted as describing the members of a set of types (or a relation on types for multi-parameter type classes). In a type signature, a universally quantified type variable constrained by a type class constraint represents a collection of types that are members of the class. E.g. for the <tt>Eq</tt> class, the following type signature describes a collection of types for which there are instances of <tt>Eq</tt>:
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt>Eq a =&gt; a</tt>
</p>
<p>
The members of <tt>Eq</tt> are a subcollection of the objects of <b>Hask</b>. Similarly, the type:
</p>
<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<tt>(Eq a, Eq b) =&gt; (a -&gt; b)</tt>
</p>
<p>
represents a subcollection of the morphisms of <b>Hask</b> mapping between objects in the subcollection of objects which are members of <tt>Eq</tt>. Thus, the <tt>Eq</tt> class defines an <i>Eq</i>-subcategory of <b>Hask</b> with the above subcollections of objects and morphisms.</p>
<p>Type classes can thus be interpreted as describing subcategories in Haskell. In a type signature, a type class constraint on a type variable thus specifies the subcategory which the type variable ranges over the objects of. We will go on to use the constraint kinds extension to define constraint-kinded type families, allowing structures from category theory to be parameterised by subcategories, encoded as type class constraints. We will use <i>functors</i> as the example in this post (more examples <a href="http://www.cl.cam.ac.uk/~dao29/drafts/subcategories-in-haskell-dorchard11.pdf">here</a>).
</p>
<h3>Functors in Haskell</h3>
<p>
In category theory, a functor provides a mapping between categories e.g. <i>F : C &rarr; D</i>, mapping the objects and morphisms of <i>C</i> to objects and morphisms of <i>D</i>. Functors preserves identities and composition between the source and target category (see <a href="http://en.wikipedia.org/wiki/Functor">Wikipedia</a> for more). An <i>endofunctor</i> is a functor where <i>C</i> and <i>D</i> are the same category. </p>
<p>
The type constructor of a parametric data type in Haskell provides an object mapping from <b>Hask</b> to <b>Hask</b> e.g. given a data type <tt>data F a = ...</tt> the type constructor <tt>F</tt> maps objects (types) of <b>Hask</b> to other objects in <b>Hask</b>. A functor in Haskell is defined by a parametric data type, providing an object mapping, and an instance of the well-known <tt>Functor</tt> class for that data type:</p>
<p><code></p>
<pre>
class Functor f where
   fmap :: (a -&gt; b) -&gt; f a -&gt; f b
</pre>
<p></code></p>
<p>which provides a mapping on morphisms, called <tt>fmap</tt>. There are many examples of functors in Haskell, for examples lists, where the <tt>fmap</tt> operation is the usual map operation, or the <tt>Maybe</tt> type. However, not all parametric data types are functors.
</p>
<p>
It is well-known that the <tt>Set</tt> data type in Haskell cannot be made an instance of the <tt>Functor</tt> class. The <tt>Data.Set</tt> library provides a map operation of type:</p>
<p><code></p>
<pre>
Set.map :: (Ord a, Ord b) =&gt; (a -&gt; b) -&gt; Set a -&gt; Set b
</pre>
<p></code></p>
<p>The <tt>Ord</tt> constraint on the element types is due to the implementation of <tt>Set</tt> using balanced binary trees, thus elements must be comparable. Whilst the data type is declared polymorphic, the constructors and transformers of <tt>Set</tt> allow only elements of a type that is an instance of <tt>Ord</tt>.
</p>
<p>
Using <tt>Set.map</tt> to define an instance of the <tt>Functor</tt> class for <tt>Set</tt> causes a type error:</p>
<p><code></p>
<pre>
instance Functor Set where
   fmap = Data.Set.map

...

foo.lhs:4:14:
    No instances for (Ord b, Ord a)
      arising from a use of `Data.Set.map'
    In the expression: Data.Set.map
    In an equation for `fmap': fmap = Data.Set.map
    In the instance declaration for `Functor Set'
</pre>
<p></code></p>
<p>The type error occurs as the signature for <tt>fmap</tt> has no constraints, or the <i>empty</i> (always true) constraint, whereas <tt>Set.map</tt> has <tt>Ord</tt> constraints. A mismatch occurs and a type error is produced.
</p>
<p>
The type error is however well justified from a mathematical perspective.
</p>
<h3>Haskell functors are not functors, but endofunctors</h3>
<p>
First of all, the name <tt>Functor</tt> is a misnomer; the class actually describes <i>endo</i>functors, that is functors which have the same category for their source and target. If we understand type class constraints as specifying a subcategory, then the lack of constraints on <tt>fmap</tt> means that <tt>Functor</tt> describes endofunctors <b>Hask</b> &rarr; <b>Hask</b>.
</p>
<p>
The <tt>Set</tt> data type is not an endofunctor; it is a functor which maps from the <i>Ord</i>-subcategory of <b>Hask</b> to <b>Hask</b>. Thus <tt>Set ::</tt> <i>Ord</i><tt> &rarr; </tt><b>Hask</b>. The class constraints on the element types in <tt>Set.map</tt> declare the subcategory of <tt>Set</tt> functor to which the morphisms belong.
</p>
<h3>Type class of <i>exo</i>functors</h3>
<p>
Can we define a type class which captures functors that are not necessarily endofunctors, but may have distinct source and target categories? Yes, using an associated type family of kind <tt>Constraint</tt>.
</p>
<p>
The following <tt>ExoFunctor</tt> type class describes a functor from a subcategory of <b>Hask</b> to <b>Hask</b>:</p>
<p><code></p>
<pre>
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeFamilies #-}

class ExoFunctor f where
   type SubCat f x :: Constraint
   fmap :: (SubCat f a, SubCat f b) =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</pre>
<p></code></p>
<p>The <tt>SubCat</tt> family defines the source subcategory for the functor, which depends on <tt>f</tt>. The target subcategory is just <b>Hask</b>, since <tt>f a</tt> and <tt>f b</tt> do not have any constraints.
</p>
<p>
We can now define the following instance for <tt>Set</tt>:</p>
<p><code></p>
<pre>
instance ExoFunctor Set where
   type SubCat Set x = Ord x
   fmap = Set.map
</pre>
<p></code></p>
<p>Endofunctors can also be made an instance of <tt>ExoFunctor</tt> using the empty constraint e.g.:</p>
<p><code></p>
<pre>
instance ExoFunctor [] where
    type SubCat [] a = ()
    fmap = map
</pre>
<p></code>
</p>
<p>(Aside: one might be wondering whether we should also have a way to restrict the target subcategory to something other than <b>Hask</b> here. By covariance we can always &#8220;cast&#8221; a functor <i>C &rarr; D</i>, where <i>D</i> is a subcategory of some other category <i>E</i>, to <i>C &rarr; E</i> without any problems. Thus, there is nothing to be gained from restricting the target to a subcategory, as it can always be reinterpreted as <b>Hask</b>.)
</p>
<h3>Conclusion (implementational restrictions = subcategories)</h3>
<p>
Subcategory constraints are needed when a data type is restricted in its polymorphism by its operations, usually because of some hidden implementational details that have permeated to the surface. These implementational details have until now been painful for Haskell programmers, and have threatened abstractions such as functors, monads, and comonads. Categorically, these implementational restrictions can be formulated succinctly with subcategories, for which there are corresponding structures of non-endofunctors, relative monads, and relative comonads. Until now there has been no succinct way to describe such structures in Haskell.
</p>
<p>Using constraint kinds we can define associated type families, of kind <tt>Constraint</tt>, which allow abstract categorical structures, described via their operations as a type class, to be parameterised by subcategories on a per-instance basis. We can thus define a class of <i>exo</i>functors, i.e. functors that are not necessarily endofunctors, which we showed here. The other related structures which are difficult to describe in Haskell without constraint kinds: <i>relative monads</i> and <i>relative comonads</i>, are discussed further <a href="http://www.cl.cam.ac.uk/~dao29/drafts/subcategories-in-haskell-dorchard11.pdf">in this draft note</a>. The note includes examples of a <i>Set</i> monad and an unboxed array comonad, both of which expose their implementational restrictions as type class constraints which can be described as subcategory constraints.<br />
Any feedback on this post or the draft note is greatly appreciated. Thanks.
</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dorchard.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dorchard.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dorchard.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dorchard.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dorchard.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dorchard.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dorchard.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dorchard.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dorchard.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dorchard.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dorchard.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dorchard.wordpress.com/136/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dorchard.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dorchard.wordpress.com/136/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=136&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://dorchard.wordpress.com/2011/10/18/subcategories-in-haskell-exofunctors/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/41c8c23e94beefb4fdf4c716c377d05d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Constraint kinds in Haskell, finally bringing us constraint families</title>
		<link>https://dorchard.wordpress.com/2011/09/22/constraint-kinds-in-haskell-finally-bringing-us-constraint-families/</link>
		<comments>https://dorchard.wordpress.com/2011/09/22/constraint-kinds-in-haskell-finally-bringing-us-constraint-families/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 10:45:06 +0000</pubDate>
		<dc:creator>dorchard</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[constraints]]></category>
		<category><![CDATA[edsl]]></category>

		<guid isPermaLink="false">http://dorchard.wordpress.com/?p=90</guid>
		<description><![CDATA[Back in 2009 Tom Schrijvers and I wrote a paper entitled Haskell Type Constraints Unleashed [1] which appeared at FLOPS 2010 in April. In the paper we fleshed out the idea of adding constraint synyonyms and constraint families to GHC/Haskell, building upon various existing proposals for class families/indexed constraints. The general idea in our paper, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=90&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style='font-size:1em;' align='justify'>
<p>
Back in 2009 <a href='http://users.ugent.be/~tschrijv/'>Tom Schrijvers</a> and I wrote a paper entitled <i>Haskell Type Constraints Unleashed</i> <a href='#cite1'>[1]</a> which appeared at <a href='http://www.kb.ecei.tohoku.ac.jp/flops2010/wiki/'>FLOPS 2010</a> in April. In the paper we fleshed out the idea of adding <i>constraint synyonyms</i> and <i>constraint families</i> to GHC/Haskell, building upon various existing proposals for <i>class families</i>/<i>indexed constraints</i>. The general idea in our paper, and in the earlier proposals, is to add a mechanism to GHC/Haskell to allow constraints, such as type class or equality constraints, to be indexed by a type in the same way that type families and data families allow types to be indexed by types.
</p>
<p>
As an example of why constraint families are useful, consider the following type class which describes a simple, polymorphic, embedded language in Haskell (in the &#8220;<i>finally tagless</i>&#8220;-style <a href='#cite2'>[2]</a>) (this example appears in <a href='#cite1'>[1]</a>):
</p>
<p><code></p>
<pre>
class Expr sem where
    constant :: a -&gt; sem a
    add :: sem a -&gt; sem a -&gt; sem a
</pre>
<p></code></p>
<p>
Instances of <tt>Expr</tt> provide different evaluation semantics for the language. For example, we might like to evaluate the language for numerical values, so we might try and write the following instance:
</p>
<p><code></p>
<pre>
data E a = E {eval :: a}

instance Expr E where
     constant c = E c
     add e1 e2 = E $ (eval e1) + (eval e2)
</pre>
<p></code></p>
<p>
However, this instance does not type check. GHC returns the type error:
</p>
<p><code></p>
<pre>
    No instance for (Num a)
      arising from a use of `+'
    In the second argument of `($)', namely `(eval e1) + (eval e2)'
    ...
</pre>
<p></code></p>
<p>
The <tt>+</tt> operation requires the <tt>Num a</tt> constraint, yet the signature for <tt>add</tt> states no constraints on type variable <tt>a</tt>, thus the constraint is never satisfied in this instance. We could add the <tt>Num a</tt> constraint to the signature of <tt>add</tt>, but this would restrict the polymorphism of the language: further instances would have this constraint forced upon them. Other useful semantics for the language may require other constraints e.g. <tt>Show a</tt> for pretty printing. Should we just add more and more constraints to the class? By no means!
</p>
<p><i>Constraint families</i>, as we describe in <a href='#cite1'>[1]</a>, provide a solution: by associating a constraint family to the class we can vary, or <i>index</i>, the constraints in the types of <tt>add</tt> and <tt>constant</tt> by the type of an instance of <tt>Expr</tt>. The solution we suggest looks something likes:</p>
<p><code></p>
<pre>
class Expr sem where
    constraint Pre sem a
    constant :: Pre sem a =&gt; a -&gt; sem a
    add :: Pre sem a =&gt; sem a -&gt; sem a -&gt; sem a

instance Expr E where
    constraint Pre E a = Num a
    ... -- methods as before
</pre>
<p></code></p>
<p><tt>Pre</tt> is the name of a constraint family that takes two type parameters and returns a constraint, where the first type parameter is the type parameter of the <tt>Expr</tt> class. </p>
<p>We could add some further instances:</p>
<p><code></p>
<pre>
data P a = P {prettyP :: a}

instance Expr P where
    constraint Pre P a = Show a
    constant c = P c
    add e1 e2 = P $ prettyP e1 ++ prettyP e2
</pre>
<p></code></p>
<p>At the time of writing the paper I had only a prototype implementation in the form of a preprocessor that desugared constraint families into some equivalent constructions (which were significantly more awkward and ugly of course). There has not been a proper implementation in GHC, or of anything similar. Until now.</p>
<p>At CamHac, the Cambridge Haskell Hackathon, last month, <a href='http://www.cl.cam.ac.uk/~mb566/'>Max Bolingbroke</a> started work on an extension for GHC called &#8220;constraint kinds&#8221;. The new extensions unifies types and constraints such that the only distinction is that constraints have a special <i>kind</i>, denoted <tt>Constraint</tt>. Thus, for example, the |Show| class constructor is actually a type constructor, of kind:</p>
<p><code></p>
<pre>
Show :: * -&gt; Constraint
</pre>
<p></code></p>
<p>For type signatures of the form <tt>C =&gt; t</tt>, the left-hand side is now a type term of kind <tt>Constraint</tt>. As another example, the equality constraints constructor <tt>~</tt> now has kind:</p>
<p><code></p>
<pre>
~ :: * -&gt; * -&gt; Constraint
</pre>
<p></code></p>
<p>i.e. it takes two types and returns a constraint.</p>
<p>Since constraints are now just types, existing type system features on type terms, such as synonyms and families, can be reused on constraints. Thus we can now define <i>constraint synonyms</i> via standard type synonms e.g.</p>
<p><code></p>
<pre>
type ShowNum a = (Num a, Show a)
</pre>
<p></code></p>
<p>And most excitingly, <i>constraint families</i> can be defined via type families of return kind <tt>Constraint</tt>. Our previous example can be written:</p>
<p><code></p>
<pre>
class Expr sem where
    type Pre sem a :: Constraint
    constant :: Pre sem a =&gt; a -&gt; sem a
    add :: Pre sem a =&gt; sem a -&gt; sem a -&gt; sem a

instance Expr E where
    type Pre E a = Num a
    ...
</pre>
<p></code></p>
<p>Thus, <tt>Pre</tt> is a type family of kind <tt>* -&gt; * -&gt; Constraint</tt>. And it all works!</p>
<p>The constraint kinds extension can be turned on via the pragma:</p>
<p><code></p>
<pre>
{-# LANGUAGE ConstraintKinds #-}
</pre>
<p></code></p>
<p>Max has written about the extension over at <a href='http://blog.omega-prime.co.uk/?p=127'>his blog</a>, which has some more examples, so do go check that out. As far as I am aware the extension should be hitting the streets with version 7.4 of GHC. But if you can&#8217;t wait it is already in the GHC HEAD revision so you can checkout a <a href='http://www.haskell.org/ghc/download'>development snapshot</a> and give it a whirl.</p>
<p>In my next post I will be showing how we can use the constraint kinds extension to describe abstract structures from category theory in Haskell that are defined upon <i>subcategories</i>. I already have a <a href='http://www.cl.cam.ac.uk/~dao29/drafts/subcategories-in-haskell-dorchard11.pdf'>draft note about this</a> if you can&#8217;t wait!</p>
<p><b><br />
<h3>References</h3>
<p></b><a name='cite1' href='http://www.cl.cam.ac.uk/~dao29/publ/constraint-families.pdf'><br />
[1] Orchard, D. Schrijvers, T.: <i>Haskell Type Constraints Unleashed</i>, FLOPS 2010</a>, [<a href='http://www.cl.cam.ac.uk/~dao29/publ/constraint-families.pdf'>author's copy with corrections</a>] [<a href='http://www.springerlink.com/content/r87810un65965001/'>On SpringerLink</a>]<br />
</a><a name='cite2'><br />
[2] Carrete, J., Kiselyov, O., Shan, C. C.: <i>Finally Tagless, Partially Evaluated</i>, APLAS 2007<br />
</a>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dorchard.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dorchard.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dorchard.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dorchard.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dorchard.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dorchard.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dorchard.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dorchard.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dorchard.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dorchard.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dorchard.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dorchard.wordpress.com/90/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dorchard.wordpress.com/90/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dorchard.wordpress.com/90/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=90&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://dorchard.wordpress.com/2011/09/22/constraint-kinds-in-haskell-finally-bringing-us-constraint-families/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/41c8c23e94beefb4fdf4c716c377d05d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>The four &#8220;R&#8221;s of programming language design</title>
		<link>https://dorchard.wordpress.com/2011/03/21/the-four-rs-of-programming-language-design/</link>
		<comments>https://dorchard.wordpress.com/2011/03/21/the-four-rs-of-programming-language-design/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 16:10:07 +0000</pubDate>
		<dc:creator>dorchard</dc:creator>
				<category><![CDATA[programming languages]]></category>
		<category><![CDATA[language design]]></category>

		<guid isPermaLink="false">http://dorchard.wordpress.com/?p=44</guid>
		<description><![CDATA[Because I have some serious work to do for an impending deadline I have become particularly good at inventing ways to not work that I can convince myself are &#8220;worthwhile&#8221;. To this end I have decided to post on my (dead) blog, which I am planning to revive with at least monthly posts. Last year [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=44&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div align='justify'>
Because I have some serious work to do for an impending deadline I have become particularly good at inventing ways to not work that I can convince myself are &#8220;worthwhile&#8221;. To this end I have decided to post on my (dead) blog, which I am planning to revive with <em>at least</em> monthly posts.</p>
<p>Last year the <a href="http://www.cl.cam.ac.uk">Cambridge Computer Lab</a> started an informal lecture course taught by PhD students aimed at final year undergraduates and MPhil students with the rough aim of providing lecturing experience to PhD students, and for disseminating more ideas from research to undergrads/MPhils/each other. In my group, the <a href="http://cprg-research.blogspot.com/">CPRG</a> (Cambridge Programming Research Group), part of the bigger <a href="http://www.cl.cam.ac.uk/research/pls/">PLS</a> (Programming, Logic, and Semantics Group), four of us decided to do a mini-series about aspects of programming language design. The slides/notes from our lectures can be found <a href="http://www.cl.cam.ac.uk/teaching/0910/RSL/">here</a> on the dates of May 10th, 11th, 14th, and 24th. </p>
<p>To bind the mini-series together we prepared an <a href="http://www.cl.cam.ac.uk/~dao29/lectures/cprg/cprg-lectures-introduction.pdf">informal, general summary of the ideas contained within</a> which concludes with the summary:</p>
<blockquote><p>
The development of programming languages, and abstraction away from<br />
machine code, has greatly aided software development. Programming lan-<br />
guages are a conduit between man and machine, with much of programming<br />
language research aiming to improve this interaction and to help us better<br />
express our ideas. We can attempt to improve languages for ease of reading,<br />
ease of writing, and ease of reasoning, and improve our evaluation systems<br />
to use less resources (whether it be processor time, memory, power, etc.)<br />
whilst still providing a predictable system. Such facets of programming<br />
language design are often non-orthogonal, thus a language designer must<br />
trade-off certain improvements for others. Often, a motivating application<br />
domain or purpose can help distill which features of a language are most<br />
important. This lecture series should give some food for thought in various<br />
areas of general programming and programming language design.
</p></blockquote>
<p>From which I offered the following general slogan:</p>
<blockquote><p>
<b>The four &#8220;R&#8221;s that programming language design must improve of programs: reading, &#8216;riting, reasoning, and running. </b>
</p></blockquote>
<p>A bit of a generalisation perhaps, but hopefully a useful &#8220;elevator-pitch&#8221; slogan to get more people thinking about programming language design, and with a bit of humour (see <a href="http://en.wikipedia.org/wiki/The_three_Rs">  The three Rs</a>).
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dorchard.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dorchard.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dorchard.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dorchard.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dorchard.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dorchard.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dorchard.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dorchard.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dorchard.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dorchard.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dorchard.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dorchard.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dorchard.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dorchard.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=44&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://dorchard.wordpress.com/2011/03/21/the-four-rs-of-programming-language-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/41c8c23e94beefb4fdf4c716c377d05d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Paper: Haskell Type Constraints Unleashed</title>
		<link>https://dorchard.wordpress.com/2009/11/04/paper-haskell-type-constraints-unleashed/</link>
		<comments>https://dorchard.wordpress.com/2009/11/04/paper-haskell-type-constraints-unleashed/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 17:59:12 +0000</pubDate>
		<dc:creator>dorchard</dc:creator>
				<category><![CDATA[paper]]></category>
		<category><![CDATA[constraints]]></category>
		<category><![CDATA[edsl]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[types]]></category>

		<guid isPermaLink="false">http://dorchard.wordpress.com/?p=32</guid>
		<description><![CDATA[Tom Schrijvers and I have a new paper describing extensions to Haskell&#8217;s type-constraint term language, which considerably increases its flexibility. These extensions are particularly useful when writing polymorphic EDSLs in Haskell, thus expanding Haskell&#8217;s capacity for embedding DSLs. Abstract: The popular Glasgow Haskell Compiler extends the Haskell 98 type system with several powerful features, leading [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=32&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div style='font-size:1em;' align='justify'>
Tom Schrijvers and I have <a href='http://www.cl.cam.ac.uk/~dao29/publ/constraint-families.pdf'>a new paper</a> describing extensions to Haskell&#8217;s type-constraint term language, which considerably increases its flexibility. These extensions are particularly useful when writing polymorphic EDSLs in Haskell, thus expanding Haskell&#8217;s capacity for embedding DSLs.</p>
<p>Abstract:</p>
<blockquote><p>
The popular Glasgow Haskell Compiler extends the Haskell 98 type system with several powerful features, leading to an expressive language of type terms. In contrast, constraints over types have received much less attention, creating an imbalance in the expressivity of the type system. In this paper, we rectify the imbalance, transferring familiar type-level constructs, <i>synonyms</i> and <i>families</i>, to the language<br />
of constraints, providing a symmetrical set of features at the type-level and constraint-level. We introduce <i>constraint synonyms</i> and <i>constraint families</i>, and illustrate their increased expressivity for improving the utility of polymorphic EDSLs in Haskell, amongst other examples. We provide a discussion of the semantics of the new features relative to existing type system features and similar proposals, including details of termination.
</p></blockquote>
<p>[<a href='http://www.cl.cam.ac.uk/~dao29/publ/constraint-families.pdf'>draft pdf</a> submitted to <a href='http://http//www.kb.ecei.tohoku.ac.jp/flops2010/wiki/'>FLOPS 2010</a>]<br />
Any feedback is most welcome. Blog posts to follow if you are too lazy to read the paper.
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dorchard.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dorchard.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dorchard.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dorchard.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dorchard.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dorchard.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dorchard.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dorchard.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dorchard.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dorchard.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dorchard.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dorchard.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dorchard.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dorchard.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=32&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://dorchard.wordpress.com/2009/11/04/paper-haskell-type-constraints-unleashed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/41c8c23e94beefb4fdf4c716c377d05d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Paper: Ypnos, Declarative Parallel Structured Grid Programming</title>
		<link>https://dorchard.wordpress.com/2009/09/29/paper-ypnos-declarative-parallel-structured-grid-programming/</link>
		<comments>https://dorchard.wordpress.com/2009/09/29/paper-ypnos-declarative-parallel-structured-grid-programming/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 17:43:03 +0000</pubDate>
		<dc:creator>dorchard</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[paper]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[comonads]]></category>
		<category><![CDATA[edsl]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[ypnos]]></category>

		<guid isPermaLink="false">http://dorchard.wordpress.com/?p=21</guid>
		<description><![CDATA[Max Bolingbroke, Alan Mycroft, and I have written a paper on a new DSL for programming structured grid computations with the view to parallelisation, called Ypnos, submitted to DAMP &#8217;10] Abstract: A fully automatic, compiler-driven approach to parallelisation can result in unpredictable time and space costs for compiled code. On the other hand, a fully [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=21&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div align='justify' style='font-size:1em;'>
Max Bolingbroke, Alan Mycroft, and I have written <a href='http://www.cl.cam.ac.uk/~dao29/publ/ypnos1.html'>a paper</a> on a new DSL for programming structured grid computations with the view to parallelisation, called Ypnos, submitted to <a href='http://damp10.cs.nmsu.edu/'>DAMP &#8217;10</a>]</p>
<p>Abstract:</p>
<blockquote><p>
A fully automatic, compiler-driven approach to parallelisation can result in unpredictable time and space costs for compiled code. On the other hand, a fully manual, human-driven approach to parallelisation can be long, tedious, prone to errors, hard to debug, and often architecture-specific. We present a declarative domain-specific language, Ypnos, for expressing structured grid computations which encourages manual specification of causally sequential operations but then allows a simple, predictable, static analysis to generate optimised, parallel implementations. We introduce the language and provide some discussion on the theoretical aspects of the language semantics, particularly the structuring of computations around the category theoretic notion of a <i>comonad</i>.
</p></blockquote>
<p>Any feedback is welcome.
</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dorchard.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dorchard.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dorchard.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dorchard.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dorchard.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dorchard.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dorchard.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dorchard.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dorchard.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dorchard.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dorchard.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dorchard.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dorchard.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dorchard.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=21&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://dorchard.wordpress.com/2009/09/29/paper-ypnos-declarative-parallel-structured-grid-programming/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/41c8c23e94beefb4fdf4c716c377d05d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dorchard</media:title>
		</media:content>
	</item>
		<item>
		<title>Talk: @BCTCS&#8217;09 &#8220;Lucian: Dataflow and Object Orientation&#8221;</title>
		<link>https://dorchard.wordpress.com/2009/04/28/talk-bctcs09-lucian-dataflow-and-object-orientation/</link>
		<comments>https://dorchard.wordpress.com/2009/04/28/talk-bctcs09-lucian-dataflow-and-object-orientation/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 23:14:54 +0000</pubDate>
		<dc:creator>dorchard</dc:creator>
				<category><![CDATA[Slides]]></category>
		<category><![CDATA[lucian]]></category>
		<category><![CDATA[lucid]]></category>

		<guid isPermaLink="false">http://dorchard.wordpress.com/?p=14</guid>
		<description><![CDATA[Slides from my BCTCS talk entitled Lucian: Dataflow and Object Orientation: BCTCS &#8217;09 was held at Warwick University- the university that I studied for my undergraduate degree at. I enjoyed the conference particularly, as I got to spend time with Steve Matthews and Sara Kalvala (my undergraduate project supervisors from my 3rd and 4th years), [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=14&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div align='justify' style='font-size:1em;'>
Slides from my BCTCS talk entitled <i>Lucian: Dataflow and Object Orientation</i>:</p>
<p align='center'>
<a href='http://www.cl.cam.ac.uk/~dao29/talks/lucian-bctcs09-dorchard.pdf'><img src='http://dorchard.g615.co.uk/content/lucian-bctcs09-dorchard.png' border='0' /></a>
</p>
<p>
BCTCS &#8217;09 was held at Warwick University- the university that I studied for my undergraduate degree at. I enjoyed the conference particularly, as I got to spend time with Steve Matthews and Sara Kalvala (my undergraduate project supervisors from my 3rd and 4th years), old friends from my undergraduate days, new friends from other universities, and also Bill Wadge, co-creator of Lucid, who was invited to speak at BCTCS &#8217;09 all the way from Victoria, Canada.</p>
<p>
If you have ever had a conversation with me about computer science you will know I have a particular proclivity for the Lucid programming language, so getting to chat about all things Lucid for a few days was great fun. Bill supervised Steve back when Bill was at Warwick, in the early days of Lucid. The quip is that Bill is my <i>grandsupervisor</i>. <br />
The Lucian language is my own object-oriented hybrid of Lucid. I started Lucian as my 3rd year project and dissertation- quite some time ago now. The ideas developed further after discussions with Bill back in 2007, resulting in Steve and I publishing a paper which came out in 2008. In January 2009, with the BCTCS looming, I thought it would be fitting to talk about Lucian at BCTCS, due to Bill and Steve being present, and BCTCS being held at Warwick, the crucible of Lucid&#8217;s youth. So I revisited Lucian and discovered that there was much more to say than was originally conveyed in the paper. I mulled Lucian over last term and have since revised the language and have had some further thoughts about its semantics.
</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dorchard.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dorchard.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dorchard.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dorchard.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dorchard.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dorchard.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dorchard.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dorchard.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dorchard.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dorchard.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dorchard.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dorchard.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dorchard.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dorchard.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=14&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://dorchard.wordpress.com/2009/04/28/talk-bctcs09-lucian-dataflow-and-object-orientation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/41c8c23e94beefb4fdf4c716c377d05d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dorchard</media:title>
		</media:content>

		<media:content url="http://dorchard.g615.co.uk/content/lucian-bctcs09-dorchard.png" medium="image" />
	</item>
		<item>
		<title>The Koch Snowflake</title>
		<link>https://dorchard.wordpress.com/2009/02/18/the-koch-snowflake/</link>
		<comments>https://dorchard.wordpress.com/2009/02/18/the-koch-snowflake/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 16:03:42 +0000</pubDate>
		<dc:creator>dorchard</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fractals]]></category>
		<category><![CDATA[maths]]></category>

		<guid isPermaLink="false">http://dorchard.wordpress.com/?p=3</guid>
		<description><![CDATA[This post has been imported from my old blog. I mentioned a couple of weeks ago I was going to write a post about a certain fractal. Now I have finally gotten round to writing something it has come at a very appropriate time as Britain has seen an unusual amount of snow recently. Sadly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=3&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span style='color:#f00;'>This post has been imported from my old blog.</span></p>
<div align='justify' style='font-size:1em;'>
I mentioned a couple of weeks ago I was going to write a post about a certain fractal. Now I have finally gotten round to writing something it has come at a very appropriate time as Britain has seen an unusual amount of snow recently. Sadly all of that snow has melted now. I am going to briefly introduce the <a href='http://en.wikipedia.org/wiki/Koch_snowflake'>Koch Snowflake</a> (also known as the Koch Island, or Koch Star) which is a <a href='http://en.wikipedia.org/wiki/Fractal'>fractal</a> with a very simple construction. I will first informally describe a geometrical construction of the fractal and will then show some of its properties, particularly the property that the fractal has an infinite length enclosing a finite area.</p>
<p><b>Construction</b><br />
The base case of the construction is an equilateral triangle. For each successive iteration the construction proceeds as follows:</p>
<ul>
<li>Divide each edge of the polygon (say of length <i>a</i>) into three equal segments of length <i>a/3</i>.</li>
<li>Replace the middle segment with an equilateral triangle of side <i>a/3.</i></li>
<li>Remove the base edge of the new equilateral triangle to form a continuous curve with other line segments.</li>
</ul>
<p>Thus each edge is transformed as such:</p>
<div align='center'>
<img src='http://dorchard.co.uk/tmp/koch/geometric-construction.png'>
</div>
<p></p>
<p>The first 5 iterations look like:</p>
<div align='center'>
<img src='http://dorchard.co.uk/tmp/koch/5-iterations-small.png'>
</div>
<p>
<b>Properties</b><br />
Two properties of this fractal may seem paradoxical at first but are easily shown. I will show the derivations here for the interested without skipping too many steps.<br />
For an infinite number of iterations the perimeter of the fractal (the length of all the edges) tends to infinity whilst the area enclosed remains finite.</p>
<p><b>Infinite Perimeter</b><br />
First consider the number of edges for an infinite number of iterations. Initially the number of edges is 3, each iteration transforms a single edge into 4 edges (see above), thus the series of the edge count is: 3, 12, 48, &#8230;. The general form is:<br />

<div align='center'>
<img src='http://dorchard.co.uk/tmp/koch/equation1.png'>
</div>
<p>
Starting from an edge length of <i>a</i> each iteration divides the edge length by 3. The following defines the edge length for iteration <i>n</i> and from this calculates the perimeter for iteration <i>n</i>. The limit as <i>n</i> tends to infinity is found, showing that the<br />
perimeter is infinite.<br />

<div align='center'>
<img src='http://dorchard.co.uk/tmp/koch/equation2.png'>
</div>
<p>
Thus it is easy to see that the perimeter length is infinite through standard results on limits. </p>
<p><b>Finite Area</b><br />
The area calculation is a little bit more involved. The result can be seen on <a href='http://mathworld.wolfram.com/KochSnowflake.html'>Mathworld</a> or <a href='http://en.wikipedia.org/wiki/Koch_snowflake'>Wikipedia</a> but a full derivation isn&#8217;t given, so I show my derivation here for the interested.</p>
<p>The area of the n-th iteration of the Koch snowflake is the area of the base triangle + the area of the new, smaller, triangles added to each edge.<br />
From the above length calculations and construction we know that each iteration of the construction divides the length of the edges by three. First consider the relationship between the area of a triangle of edge length <i>a</i> and a triangle of edge length <i>a/3</i></p>
<div align='center'>
<table width='100%'>
<tr>
<td width='50%'>
<div align='center'>
<img src='http://dorchard.co.uk/tmp/koch/triangle-scale-1.png'>
</div>
</td>
<td width='50%'>
<div align='center'>
<img src='http://dorchard.co.uk/tmp/koch/triangle-scale-third.png'>
</div>
</td>
</tr>
<td width='50%'>
<div align='center'>
<img src='http://dorchard.co.uk/tmp/koch/area-equation1.png'>
</div>
</td>
<td width='50%'>
<div align='center'>
<img src='http://dorchard.co.uk/tmp/koch/area-equation2.png'>
</div>
</td>
</tr>
</table>
</div>
<p>Unsurprisingly we see that dividing the edge length by 3 divides the area by 9. At each iteration we add new equilateral triangles to each edge, a ninth of the area of the previous iteration&#8217;s triangles.<br />
We formulate this as a summation of base case <i>A0</i> plus the next <i>n-1</i> iterations where the triangle area at each stage is <i>A0</i> divided by <i>3<sup>2n</sup></i> or <i>9<sup>n</sup></i> (successive divisions of the area by 9). The number of edges is defined by the previous iterations number of edges <i>3 * 4<sup>n-1</sup></i>, thus at the <i>n</i>-th iteration we need to add this number of triangles to the snowflake.</p>
<div align='center'>
<img src='http://dorchard.co.uk/tmp/koch/equation3.png'>
</div>
<p>
Thus the area is finite at <i>8/5</i> times the area of the base equilateral triangle.</p>
<p><b>Summary</b><br />
So the Koch snowflake construction has been introduced and it has been shown relatively easily that the area of a Koch snowflake tends to a finite limit of <i>8/5</i> times the base case area (5) and that the length of perimeter tends to infinity (4). Next time I will probably talk a bit about the <i>fractal dimension</i> of the Koch snowflake and also show an interesting problem that uses the Koch snowflake.</p>
<p>As a last note, following on from the blog post I made about the Python turtle library, a turtle program of the Koch snowflake for Python can be <a href='http://dorchard.co.uk/tmp/koch/koch.py'>downloaded here</a>.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dorchard.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dorchard.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dorchard.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dorchard.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dorchard.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dorchard.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dorchard.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dorchard.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dorchard.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dorchard.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dorchard.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dorchard.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dorchard.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dorchard.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dorchard.wordpress.com&amp;blog=10180011&amp;post=3&amp;subd=dorchard&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://dorchard.wordpress.com/2009/02/18/the-koch-snowflake/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/41c8c23e94beefb4fdf4c716c377d05d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dorchard</media:title>
		</media:content>

		<media:content url="http://dorchard.co.uk/tmp/koch/geometric-construction.png" medium="image" />

		<media:content url="http://dorchard.co.uk/tmp/koch/5-iterations-small.png" medium="image" />

		<media:content url="http://dorchard.co.uk/tmp/koch/equation1.png" medium="image" />

		<media:content url="http://dorchard.co.uk/tmp/koch/equation2.png" medium="image" />

		<media:content url="http://dorchard.co.uk/tmp/koch/triangle-scale-1.png" medium="image" />

		<media:content url="http://dorchard.co.uk/tmp/koch/triangle-scale-third.png" medium="image" />

		<media:content url="http://dorchard.co.uk/tmp/koch/area-equation1.png" medium="image" />

		<media:content url="http://dorchard.co.uk/tmp/koch/area-equation2.png" medium="image" />

		<media:content url="http://dorchard.co.uk/tmp/koch/equation3.png" medium="image" />
	</item>
	</channel>
</rss>
