<?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>Wolfgang Jeltsch</title>
	<atom:link href="http://jeltsch.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeltsch.wordpress.com</link>
	<description>Mathematics, computer science, and computers</description>
	<lastBuildDate>Wed, 15 May 2013 11:53:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jeltsch.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Wolfgang Jeltsch</title>
		<link>http://jeltsch.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jeltsch.wordpress.com/osd.xml" title="Wolfgang Jeltsch" />
	<atom:link rel='hub' href='http://jeltsch.wordpress.com/?pushpress=hub'/>
		<item>
		<title>ucs 2.2 released</title>
		<link>http://jeltsch.wordpress.com/2013/05/15/ucs-2-2-released/</link>
		<comments>http://jeltsch.wordpress.com/2013/05/15/ucs-2-2-released/#comments</comments>
		<pubDate>Wed, 15 May 2013 11:52:59 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CTAN]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[software release]]></category>
		<category><![CDATA[StackExchange]]></category>
		<category><![CDATA[TeX]]></category>
		<category><![CDATA[ucs (LaTeX package)]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=597</guid>
		<description><![CDATA[I have released a new version of the LaTeX ucs package yesterday, which is version 2.2. It fixes the bug that is described in the TeX StackExchange question Conflict between ifxetex and ucs under pdflatex/xelatex &#8211; why?. Tagged: CTAN, LaTeX, software release, StackExchange, TeX, ucs (LaTeX package), Unicode<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=597&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I have released a new version of the LaTeX <em>ucs</em> package yesterday, which is version 2.2. It fixes the bug that is described in the TeX StackExchange question <a href="http://tex.stackexchange.com/questions/113261/conflict-between-ifxetex-and-ucs-under-pdflatex-xelatex-why" title="Conflict between ifxetex and ucs under pdflatex/xelatex - why?"><em>Conflict between ifxetex and ucs under pdflatex/xelatex &#8211; why?</em></a>.</p>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/ctan/'>CTAN</a>, <a href='http://jeltsch.wordpress.com/tag/latex/'>LaTeX</a>, <a href='http://jeltsch.wordpress.com/tag/software-release/'>software release</a>, <a href='http://jeltsch.wordpress.com/tag/stackexchange/'>StackExchange</a>, <a href='http://jeltsch.wordpress.com/tag/tex/'>TeX</a>, <a href='http://jeltsch.wordpress.com/tag/ucs-latex-package/'>ucs (LaTeX package)</a>, <a href='http://jeltsch.wordpress.com/tag/unicode/'>Unicode</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/597/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/597/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=597&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2013/05/15/ucs-2-2-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
		<item>
		<title>A taste of Curry</title>
		<link>http://jeltsch.wordpress.com/2013/04/27/a-taste-of-curry/</link>
		<comments>http://jeltsch.wordpress.com/2013/04/27/a-taste-of-curry/#comments</comments>
		<pubDate>Sat, 27 Apr 2013 19:06:45 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[breadth-first search]]></category>
		<category><![CDATA[Curry]]></category>
		<category><![CDATA[Denis Firsov]]></category>
		<category><![CDATA[depth-first search]]></category>
		<category><![CDATA[functional logic programming]]></category>
		<category><![CDATA[functional pattern]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[KiCS2]]></category>
		<category><![CDATA[literate programming]]></category>
		<category><![CDATA[logic programming]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[Prolog]]></category>
		<category><![CDATA[Theory Lunch]]></category>
		<category><![CDATA[TTÜ Küberneetika Instituut]]></category>
		<category><![CDATA[type class]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=587</guid>
		<description><![CDATA[Curry is a programming language that integrates functional and logic programming. Last week, Denis Firsov and I had a look at Curry, and Thursday, I gave an introductory talk about Curry in the Theory Lunch. This blog post is mostly a write-up of my talk. Like Haskell, Curry has support for literate programming. So I [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=587&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://www-ps.informatik.uni-kiel.de/currywiki/" title="Curry">Curry</a> is a programming language that <a href="http://www.informatik.uni-kiel.de/~mh/FLP/" title="Functional logic programming">integrates functional and logic programming</a>. Last week, <a href="http://cs.ioc.ee/dept/staff/denis.html" title="Denis Firsov">Denis Firsov</a> and I had a look at Curry, and Thursday, I gave an introductory talk about Curry in the <a href="http://theorylunch.wordpress.com/" title="Theory Lunch">Theory Lunch</a>. This blog post is mostly a write-up of my talk.<span id="more-587"></span></p>
<p>Like Haskell, Curry has support for literate programming. So I wrote this blog post as a literate Curry file, which is <a href="http://darcs.wolfgang.jeltsch.info/blog/2013/04/27/ATasteOfCurry.lcurry" title="A taste of Curry">available for download</a>. If you want to try out the code, you have to install the Curry system <a href="http://www-ps.informatik.uni-kiel.de/kics2/" title="KiCS2">KiCS2</a>. The code uses the functional patterns language extension, which is only supported by KiCS2, as far as I know.</p>
<h2 id="functional-programming">Functional programming</h2>
<p>The functional fragment of Curry is very similar to Haskell. The only fundamental difference is that Curry does not support type classes.</p>
<p>Let us do some functional programming in Curry. First, we define a type whose values denote me and some of my relatives.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Person</span> <span class="fu">=</span> <span class="dt">Paul</span>
            <span class="fu">|</span> <span class="dt">Joachim</span>
            <span class="fu">|</span> <span class="dt">Rita</span>
            <span class="fu">|</span> <span class="dt">Wolfgang</span>
            <span class="fu">|</span> <span class="dt">Veronika</span>
            <span class="fu">|</span> <span class="dt">Johanna</span>
            <span class="fu">|</span> <span class="dt">Jonathan</span>
            <span class="fu">|</span> <span class="dt">Jaromir</span></code></pre>
<p>Now we define a function that yields the father of a given person if this father is covered by the <code>Person</code> type.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">father ::</span> <span class="dt">Person</span> <span class="ot">-&gt;</span> <span class="dt">Person</span>
father <span class="dt">Joachim</span>  <span class="fu">=</span> <span class="dt">Paul</span>
father <span class="dt">Rita</span>     <span class="fu">=</span> <span class="dt">Joachim</span>
father <span class="dt">Wolfgang</span> <span class="fu">=</span> <span class="dt">Joachim</span>
father <span class="dt">Veronika</span> <span class="fu">=</span> <span class="dt">Joachim</span>
father <span class="dt">Johanna</span>  <span class="fu">=</span> <span class="dt">Wolfgang</span>
father <span class="dt">Jonathan</span> <span class="fu">=</span> <span class="dt">Wolfgang</span>
father <span class="dt">Jaromir</span>  <span class="fu">=</span> <span class="dt">Wolfgang</span></code></pre>
<p>Based on <code>father</code>, we define a function for computing grandfathers. To keep things simple, we only consider fathers of fathers to be grandfathers, not fathers of mothers.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">grandfather ::</span> <span class="dt">Person</span> <span class="ot">-&gt;</span> <span class="dt">Person</span>
grandfather <span class="fu">=</span> father <span class="fu">.</span> father</code></pre>
<h2 id="combining-functional-and-logic-programming">Combining functional and logic programming</h2>
<p>Logic programming languages like Prolog are able to search for variable assignments that make a given proposition true. Curry, on the other hand, can search for variable assignments that make a certain expression defined.</p>
<p>For example, we can search for all persons that have a grandfather according to the above data. We just enter</p>
<p style="text-align:center;"><code>grandfather person <span class="kw">where</span> person <span class="kw">free</span></code></p>
<p>at the KiCS2 prompt. KiCS2 then outputs all assignments to the <code>person</code> variable for which <code>grandfather person</code> is defined. For each of these assignments, it additionally prints the result of the expression <code>grandfather person</code>.</p>
<h2 id="nondeterminism">Nondeterminism</h2>
<p>Functions in Curry can actually be non-deterministic, that is, they can return multiple results. For example, we can define a function <code>element</code> that returns any element of a given list. To achieve this, we use overlapping patterns in our function definition. If several equations of a function definition match a particular function application, Curry takes all of them, not only the first one, as Haskell does.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">element ::</span> [el] <span class="ot">-&gt;</span> el
element (el <span class="fu">:</span> _)   <span class="fu">=</span> el
element (_  <span class="fu">:</span> els) <span class="fu">=</span> element els</code></pre>
<p>Now we can enter</p>
<p style="text-align:center;"><code>element &quot;Hello!&quot;</code></p>
<p>at the KiCS2 prompt, and the system outputs six different results.</p>
<h2 id="logic-programming">Logic programming</h2>
<p>We have already seen how to combine functional and logic programming with Curry. Now we want to do pure logic programming. This means that we only want to search for variable assignments, but are not interested in expression results. If you are not interested in results, you typically use a result type with only a single value. Curry provides the type <code>Success</code> with the single value <code>success</code> for doing logic programming.</p>
<p>Let us write some example code about routes between countries. We first introduce a type of some European and American countries.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Country</span> <span class="fu">=</span> <span class="dt">Canada</span>
             <span class="fu">|</span> <span class="dt">Estonia</span>
             <span class="fu">|</span> <span class="dt">Germany</span>
             <span class="fu">|</span> <span class="dt">Latvia</span>
             <span class="fu">|</span> <span class="dt">Lithuania</span>
             <span class="fu">|</span> <span class="dt">Mexico</span>
             <span class="fu">|</span> <span class="dt">Poland</span>
             <span class="fu">|</span> <span class="dt">Russia</span>
             <span class="fu">|</span> <span class="dt">USA</span></code></pre>
<p>Now we want to define a relation called <code>borders</code> that tells us which country borders which other country. We implement this relation as a function of type</p>
<p style="text-align:center;"><code>Country -&gt; Country -&gt; Success</code></p>
<p>that has the trivial result <code>success</code> if the first country borders the second one, and has no result otherwise.</p>
<p>Note that this approach of implementing a relation is different from what we do in functional programming. In functional programming, we use <code>Bool</code> as the result type and signal falsity by the result <code>False</code>. In Curry, however, we signal falsity by the absence of a result.</p>
<p>Our <code>borders</code> relation only relates countries with those neighbouring countries whose names come later in alphabetical order. We will soon compute the symmetric closure of <code>borders</code> to also get the opposite relationships.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">borders ::</span> <span class="dt">Country</span> <span class="ot">-&gt;</span> <span class="dt">Country</span> <span class="ot">-&gt;</span> <span class="dt">Success</span>
<span class="dt">Canada</span>    <span class="ot">`borders`</span> <span class="dt">USA</span>       <span class="fu">=</span> success
<span class="dt">Estonia</span>   <span class="ot">`borders`</span> <span class="dt">Latvia</span>    <span class="fu">=</span> success
<span class="dt">Estonia</span>   <span class="ot">`borders`</span> <span class="dt">Russia</span>    <span class="fu">=</span> success
<span class="dt">Germany</span>   <span class="ot">`borders`</span> <span class="dt">Poland</span>    <span class="fu">=</span> success
<span class="dt">Latvia</span>    <span class="ot">`borders`</span> <span class="dt">Lithuania</span> <span class="fu">=</span> success
<span class="dt">Latvia</span>    <span class="ot">`borders`</span> <span class="dt">Russia</span>    <span class="fu">=</span> success
<span class="dt">Lithuania</span> <span class="ot">`borders`</span> <span class="dt">Poland</span>    <span class="fu">=</span> success
<span class="dt">Mexico</span>    <span class="ot">`borders`</span> <span class="dt">USA</span>       <span class="fu">=</span> success</code></pre>
<p>Now we want to define a relation <code>isConnected</code> that tells whether two countries can be reached from each other via a land route. Clearly, <code>isConnected</code> is the equivalence relation that is generated by <code>borders</code>. In Prolog, we would write clauses that directly express this relationship between <code>borders</code> and <code>isConnected</code>. In Curry, on the other hand, we can write a function that generates an equivalence relation from any given relation and therefore does not only work with <code>borders</code>.</p>
<p>We first define a type alias <code>Relation</code> for the sake of convenience.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">type</span> <span class="dt">Relation</span> val <span class="fu">=</span> val <span class="ot">-&gt;</span> val <span class="ot">-&gt;</span> <span class="dt">Success</span></code></pre>
<p>Now we define what reflexive, symmetric, and transitive closures are.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">reflClosure ::</span> <span class="dt">Relation</span> val <span class="ot">-&gt;</span> <span class="dt">Relation</span> val
reflClosure rel val1 val2 <span class="fu">=</span> rel val1 val2
reflClosure rel val  val  <span class="fu">=</span> success

<span class="ot">symClosure ::</span> <span class="dt">Relation</span> val <span class="ot">-&gt;</span> <span class="dt">Relation</span> val
symClosure rel val1 val2 <span class="fu">=</span> rel val1 val2
symClosure rel val2 val1 <span class="fu">=</span> rel val1 val2

<span class="ot">transClosure ::</span> <span class="dt">Relation</span> val <span class="ot">-&gt;</span> <span class="dt">Relation</span> val
transClosure rel val1 val2 <span class="fu">=</span> rel val1 val2
transClosure rel val1 val3 <span class="fu">=</span> rel val1 val2 <span class="fu">&amp;</span>
                             transClosure rel val2 val3

    <span class="kw">where</span> val2 <span class="kw">free</span></code></pre>
<p>The operator <code>&amp;</code> used in the definition of <code>transClosure</code> has type</p>
<p style="text-align:center;"><code>Success -&gt; Success -&gt; Success</code></p>
<p>and denotes conjunction.</p>
<p>We define the function for generating equivalence relations as a composition of the above closure operators. Note that it is crucial that the transitive closure operator is applied after the symmetric closure operator, since the symmetric closure of a transitive relation is not necessarily transitive.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">equivalence ::</span> <span class="dt">Relation</span> val <span class="ot">-&gt;</span> <span class="dt">Relation</span> val
equivalence <span class="fu">=</span> reflClosure <span class="fu">.</span> transClosure <span class="fu">.</span> symClosure</code></pre>
<p>The implementation of <code>isConnected</code> is now trivial.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">isConnected ::</span> <span class="dt">Country</span> <span class="ot">-&gt;</span> <span class="dt">Country</span> <span class="ot">-&gt;</span> <span class="dt">Success</span>
isConnected <span class="fu">=</span> equivalence borders</code></pre>
<p>Now we let KiCS2 compute which countries I can reach from Estonia without a ship or plane. We do so by entering</p>
<p style="text-align:center;"><code>Estonia `isConnected` country <span class="kw">where</span> country <span class="kw">free</span></code></p>
<p>at the prompt.</p>
<p>We can also implement a nondeterministic function that turns a country into the countries connected to it. For this, we use a guard that is of type <code>Success</code>. Such a guard succeeds if it has a result at all, which can only be <code>success</code>, of course.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">connected ::</span> <span class="dt">Country</span> <span class="ot">-&gt;</span> <span class="dt">Country</span>
connected country1
    <span class="fu">|</span> country1 <span class="ot">`isConnected`</span> country2 <span class="fu">=</span> country2

    <span class="kw">where</span> country2 <span class="kw">free</span></code></pre>
<h2 id="equational-constraints">Equational constraints</h2>
<p>Curry has a predefined operator</p>
<p style="text-align:center;"><code>=:= :: val -&gt; val -&gt; Success</code></p>
<p>that stands for equality.</p>
<p>We can use this operator, for example, to define a nondeterministic function that yields the grandchildren of a given person. Again, we keep things simple by only considering relationships that solely go via fathers.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">grandchild ::</span> <span class="dt">Person</span> <span class="ot">-&gt;</span> <span class="dt">Person</span>
grandchild person
    <span class="fu">|</span> grandfather grandkid <span class="fu">=:=</span> person <span class="fu">=</span> grandkid

    <span class="kw">where</span> grandkid <span class="kw">free</span></code></pre>
<p>Note that <code>grandchild</code> is the inverse of <code>grandfather</code>.</p>
<h2 id="functional-patterns">Functional patterns</h2>
<p>Functional patterns are a language extension that allows us to use ordinary functions in patterns, not just data constructors. Functional patterns are implemented by KiCS2.</p>
<p>Let us look at an example again. We want to define a function <code>split</code> that nondeterministically splits a list into two parts.<sup><a href="#fn1" class="footnoteRef" id="fnref1">1</a></sup> Without functional patterns, we can implement splitting as follows.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">split&#039; ::</span> [el] <span class="ot">-&gt;</span> ([el],[el])
split&#039; list <span class="fu">|</span> front <span class="fu">++</span> rear <span class="fu">=:=</span> list <span class="fu">=</span> (front,rear)

    <span class="kw">where</span> front, rear <span class="kw">free</span></code></pre>
<p>With functional patterns, we can implement splitting in a much simpler way.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">split ::</span> [el] <span class="ot">-&gt;</span> ([el],[el])
split (front <span class="fu">++</span> rear) <span class="fu">=</span> (front,rear)</code></pre>
<p>As a second example, let us define a function <code>sublist</code> that yields the sublists of a given list.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">sublist ::</span> [el] <span class="ot">-&gt;</span> [el]
sublist (_ <span class="fu">++</span> sub <span class="fu">++</span> _) <span class="fu">=</span> sub</code></pre>
<h2 id="inverting-functions">Inverting functions</h2>
<p>In the <code>grandchild</code> example, we showed how we can define the inverse of a particular function. We can go further and implement a generic function inversion operator.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">inverse ::</span> (val <span class="ot">-&gt;</span> val&#039;) <span class="ot">-&gt;</span> (val&#039; <span class="ot">-&gt;</span> val)
inverse fun val&#039; <span class="fu">|</span> fun val <span class="fu">=:=</span> val&#039; <span class="fu">=</span> val <span class="kw">where</span> val <span class="kw">free</span></code></pre>
<p>With this operator, we could also implement <code>grandchild</code> as <code>inverse grandfather</code>.</p>
<p>Inverting functions can make our lives a lot easier. Consider the example of parsing. A parser takes a string and returns a syntax tree. Writing a parser directly is a non-trivial task. However, generating a string from a syntax tree is just a simple functional programming exercise. So we can implement a parser in a simple way by writing a converter from syntax trees to strings and inverting it.</p>
<p>We show this for the language of all arithmetic expressions that can be built from addition, multiplication, and integer constants. We first define types for representing abstract syntax trees. These types resemble a grammar that takes precedence into account.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">type</span> <span class="dt">Expr</span> <span class="fu">=</span> <span class="dt">Sum</span>

<span class="kw">data</span> <span class="dt">Sum</span>     <span class="fu">=</span> <span class="dt">Sum</span> <span class="dt">Product</span> [<span class="dt">Product</span>]
<span class="kw">data</span> <span class="dt">Product</span> <span class="fu">=</span> <span class="dt">Product</span> <span class="dt">Atom</span> [<span class="dt">Atom</span>]
<span class="kw">data</span> <span class="dt">Atom</span>    <span class="fu">=</span> <span class="dt">Num</span> <span class="dt">Int</span> <span class="fu">|</span> <span class="dt">Para</span> <span class="dt">Sum</span></code></pre>
<p>Now we implement the conversion from abstract syntax trees to strings.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">toString ::</span> <span class="dt">Expr</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
toString <span class="fu">=</span> sumToString

<span class="ot">sumToString ::</span> <span class="dt">Sum</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
sumToString (<span class="dt">Sum</span> <span class="fu">product</span> products)
    <span class="fu">=</span> productToString <span class="fu">product</span>                           <span class="fu">++</span>
      <span class="fu">concatMap</span> ((<span class="st">&quot; + &quot;</span> <span class="fu">++</span>) <span class="fu">.</span> productToString) products

<span class="ot">productToString ::</span> <span class="dt">Product</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
productToString (<span class="dt">Product</span> atom atoms)
    <span class="fu">=</span> atomToString atom                           <span class="fu">++</span>
      <span class="fu">concatMap</span> ((<span class="st">&quot; * &quot;</span> <span class="fu">++</span>) <span class="fu">.</span> atomToString) atoms

<span class="ot">atomToString ::</span> <span class="dt">Atom</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
atomToString (<span class="dt">Num</span> num)  <span class="fu">=</span> <span class="fu">show</span> num
atomToString (<span class="dt">Para</span> <span class="fu">sum</span>) <span class="fu">=</span> <span class="st">&quot;(&quot;</span> <span class="fu">++</span> sumToString <span class="fu">sum</span> <span class="fu">++</span> <span class="st">&quot;)&quot;</span></code></pre>
<p>Implementing the parser is now extremely simple.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">parse ::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">Expr</span>
parse <span class="fu">=</span> inverse toString</code></pre>
<p>KiCS2 uses a depth-first search strategy by default. However, our parser implementation does not work with depth-first search. So we switch to breadth-first search by entering</p>
<p style="text-align:center;"><code>:set bfs</code></p>
<p>at the KiCS2 prompt. Now we can try out the parser by entering</p>
<p style="text-align:center;"><code>parse &quot;2 * (3 + 4)&quot;</code> .</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn1">
<p>Note that our <code>split</code> function is not the same as the <code>split</code> function in Curry’s <code>List</code> module.<a href="#fnref1">↩</a></p>
</li>
</ol>
</div>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/breadth-first-search/'>breadth-first search</a>, <a href='http://jeltsch.wordpress.com/tag/curry/'>Curry</a>, <a href='http://jeltsch.wordpress.com/tag/denis-firsov/'>Denis Firsov</a>, <a href='http://jeltsch.wordpress.com/tag/depth-first-search/'>depth-first search</a>, <a href='http://jeltsch.wordpress.com/tag/functional-logic-programming/'>functional logic programming</a>, <a href='http://jeltsch.wordpress.com/tag/functional-pattern/'>functional pattern</a>, <a href='http://jeltsch.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://jeltsch.wordpress.com/tag/kics2/'>KiCS2</a>, <a href='http://jeltsch.wordpress.com/tag/literate-programming/'>literate programming</a>, <a href='http://jeltsch.wordpress.com/tag/logic-programming/'>logic programming</a>, <a href='http://jeltsch.wordpress.com/tag/parsing/'>parsing</a>, <a href='http://jeltsch.wordpress.com/tag/prolog/'>Prolog</a>, <a href='http://jeltsch.wordpress.com/tag/theory-lunch/'>Theory Lunch</a>, <a href='http://jeltsch.wordpress.com/tag/ttu-kuberneetika-instituut/'>TTÜ Küberneetika Instituut</a>, <a href='http://jeltsch.wordpress.com/tag/type-class/'>type class</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/587/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/587/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=587&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2013/04/27/a-taste-of-curry/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
		<item>
		<title>MIU in Haskell</title>
		<link>http://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/</link>
		<comments>http://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 13:25:02 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Douglas Hofstadter]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[Gödel, Escher, Bach (book)]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[James Chapman]]></category>
		<category><![CDATA[literate programming]]></category>
		<category><![CDATA[MU puzzle]]></category>
		<category><![CDATA[string rewriting]]></category>
		<category><![CDATA[Theory Lunch]]></category>
		<category><![CDATA[TTÜ Küberneetika Instituut]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=582</guid>
		<description><![CDATA[In the Theory Lunch of the last week, James Chapman talked about the MU puzzle from Douglas Hofstadter’s book Gödel, Escher, Bach. This puzzle is about a string rewriting system. James presented a Haskell program that computes derivations of strings. Inspired by this, I wrote my own implementation, with the goal of improving efficiency. This [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=582&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In the <a href="http://theorylunch.wordpress.com/" title="Theory Lunch">Theory Lunch</a> of the last week, <a href="http://cs.ioc.ee/~james/" title="James Chapman">James Chapman</a> talked about the <a href="http://en.wikipedia.org/wiki/MU_puzzle" title="MU puzzle">MU puzzle</a> from Douglas Hofstadter’s book <em>Gödel, Escher, Bach</em>. This puzzle is about a string rewriting system. James presented a Haskell program that computes derivations of strings. Inspired by this, I wrote my own implementation, with the goal of improving efficiency. This blog post presents this implementation. As usual, it is available as <a href="http://darcs.wolfgang.jeltsch.info/blog/2013/04/18/miu-in-haskell.lhs" title="MIU in Haskell">a literate Haskell file</a>, which you can load into GHCi.<span id="more-582"></span></p>
<h2 id="the-puzzle">The puzzle</h2>
<p>Let me first describe the MU puzzle shortly. The puzzle deals with strings that may contain the characters <img src='http://s0.wp.com/latex.php?latex=%5Cmathrm+M&amp;bg=f7f3ee&amp;fg=333333&amp;s=0' alt='&#92;mathrm M' title='&#92;mathrm M' class='latex' />, <img src='http://s0.wp.com/latex.php?latex=%5Cmathrm+I&amp;bg=f7f3ee&amp;fg=333333&amp;s=0' alt='&#92;mathrm I' title='&#92;mathrm I' class='latex' />, and <img src='http://s0.wp.com/latex.php?latex=%5Cmathrm+U&amp;bg=f7f3ee&amp;fg=333333&amp;s=0' alt='&#92;mathrm U' title='&#92;mathrm U' class='latex' />. We can derive new strings from old ones using the following rewriting system:</p>
<p style="text-align:center;"><img src='http://s0.wp.com/latex.php?latex=%5Cbegin%7Barray%7D%7Brcl%7D+x%5Cmathrm+I+%26+%5Crightarrow+%26+x%5Cmathrm%7BIU%7D+%5C%5C+%5Cmathrm+Mx+%26+%5Crightarrow+%26+%5Cmathrm+Mxx+%5C%5C+x%5Cmathrm%7BIII%7Dy+%26+%5Crightarrow+%26+x%5Cmathrm+Uy+%5C%5C+x%5Cmathrm%7BUU%7Dy+%26+%5Crightarrow+%26+xy+%5Cend%7Barray%7D+&amp;bg=f7f3ee&amp;fg=333333&amp;s=0' alt='&#92;begin{array}{rcl} x&#92;mathrm I &amp; &#92;rightarrow &amp; x&#92;mathrm{IU} &#92;&#92; &#92;mathrm Mx &amp; &#92;rightarrow &amp; &#92;mathrm Mxx &#92;&#92; x&#92;mathrm{III}y &amp; &#92;rightarrow &amp; x&#92;mathrm Uy &#92;&#92; x&#92;mathrm{UU}y &amp; &#92;rightarrow &amp; xy &#92;end{array} ' title='&#92;begin{array}{rcl} x&#92;mathrm I &amp; &#92;rightarrow &amp; x&#92;mathrm{IU} &#92;&#92; &#92;mathrm Mx &amp; &#92;rightarrow &amp; &#92;mathrm Mxx &#92;&#92; x&#92;mathrm{III}y &amp; &#92;rightarrow &amp; x&#92;mathrm Uy &#92;&#92; x&#92;mathrm{UU}y &amp; &#92;rightarrow &amp; xy &#92;end{array} ' class='latex' /></p>
<p>The question is whether it is possible to turn the string <img src='http://s0.wp.com/latex.php?latex=%5Cmathrm%7BMI%7D&amp;bg=f7f3ee&amp;fg=333333&amp;s=0' alt='&#92;mathrm{MI}' title='&#92;mathrm{MI}' class='latex' /> into the string <img src='http://s0.wp.com/latex.php?latex=%5Cmathrm%7BMU%7D&amp;bg=f7f3ee&amp;fg=333333&amp;s=0' alt='&#92;mathrm{MU}' title='&#92;mathrm{MU}' class='latex' /> using these rules.</p>
<p>You may want to try to solve this puzzle yourself, or you may want to look up the solution on the <a href="http://en.wikipedia.org/wiki/MU_puzzle" title="MU puzzle">Wikipedia page</a>.</p>
<h2 id="the-code">The code</h2>
<p>The code is not only concerned with deriving <img src='http://s0.wp.com/latex.php?latex=%5Cmathrm%7BMU%7D&amp;bg=f7f3ee&amp;fg=333333&amp;s=0' alt='&#92;mathrm{MU}' title='&#92;mathrm{MU}' class='latex' /> from <img src='http://s0.wp.com/latex.php?latex=%5Cmathrm%7BMI%7D&amp;bg=f7f3ee&amp;fg=333333&amp;s=0' alt='&#92;mathrm{MI}' title='&#92;mathrm{MI}' class='latex' />, but with derivations as such.</p>
<h3 id="preliminaries">Preliminaries</h3>
<p>We import <code>Data.List</code>:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Data.List</span></code></pre>
<h3 id="basic-things">Basic things</h3>
<p>We define the type <code>Sym</code> of symbols and the type <code>Str</code> of symbol strings:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Sym</span> <span class="fu">=</span> <span class="dt">M</span> <span class="fu">|</span> <span class="dt">I</span> <span class="fu">|</span> <span class="dt">U</span> <span class="kw">deriving</span> <span class="kw">Eq</span>

<span class="kw">type</span> <span class="dt">Str</span> <span class="fu">=</span> [<span class="dt">Sym</span>]

<span class="kw">instance</span> <span class="kw">Show</span> <span class="dt">Sym</span> <span class="kw">where</span>

    <span class="fu">show</span> <span class="dt">M</span> <span class="fu">=</span> <span class="st">&quot;M&quot;</span>
    <span class="fu">show</span> <span class="dt">I</span> <span class="fu">=</span> <span class="st">&quot;I&quot;</span>
    <span class="fu">show</span> <span class="dt">U</span> <span class="fu">=</span> <span class="st">&quot;U&quot;</span>

    <span class="fu">showList</span> str <span class="fu">=</span> (<span class="fu">concatMap</span> <span class="fu">show</span> str <span class="fu">++</span>)</code></pre>
<p>Next, we define the type <code>Rule</code> of rules as well as the list <code>rules</code> that contains all rules:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Rule</span> <span class="fu">=</span> <span class="dt">R1</span> <span class="fu">|</span> <span class="dt">R2</span> <span class="fu">|</span> <span class="dt">R3</span> <span class="fu">|</span> <span class="dt">R4</span> <span class="kw">deriving</span> <span class="kw">Show</span>

<span class="ot">rules ::</span> [<span class="dt">Rule</span>]
rules <span class="fu">=</span> [<span class="dt">R1</span>,<span class="dt">R2</span>,<span class="dt">R3</span>,<span class="dt">R4</span>]</code></pre>
<h3 id="rule-application">Rule application</h3>
<p>We first introduce a helper function that takes a string and returns the list of all splits of this string. Thereby, a split of a string <code>str</code> is a pair of strings <code>str1</code> and <code>str2</code> such that <code>str1 ++ str2 == str</code>. A straightforward implementation of splitting is as follows:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">splits&#039; ::</span> <span class="dt">Str</span> <span class="ot">-&gt;</span> [(<span class="dt">Str</span>,<span class="dt">Str</span>)]
splits&#039; str <span class="fu">=</span> <span class="fu">zip</span> (inits str) (tails str)</code></pre>
<p>The problem with this implementation is that walking through the result list takes quadratic time, even if the elements of the list are left unevaluated. The following implementation solves this problem:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">splits ::</span> <span class="dt">Str</span> <span class="ot">-&gt;</span> [(<span class="dt">Str</span>,<span class="dt">Str</span>)]
splits str <span class="fu">=</span> <span class="fu">zip</span> (<span class="fu">map</span> (<span class="fu">flip</span> <span class="fu">take</span> str) [<span class="dv">0</span> <span class="fu">..</span>]) (tails str)</code></pre>
<p>Next, we define a helper function <code>replace</code>. An expression <code>replace old new str</code> yields the list of all strings that can be constructed by replacing the string <code>old</code> inside <code>str</code> by <code>new</code>.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">replace ::</span> <span class="dt">Str</span> <span class="ot">-&gt;</span> <span class="dt">Str</span> <span class="ot">-&gt;</span> <span class="dt">Str</span> <span class="ot">-&gt;</span> [<span class="dt">Str</span>]
replace old new str <span class="fu">=</span> [front <span class="fu">++</span> new <span class="fu">++</span> rear <span class="fu">|</span>
                          (front,rest) <span class="ot">&lt;-</span> splits str,
                          old <span class="ot">`isPrefixOf`</span> rest,
                          <span class="kw">let</span> rear <span class="fu">=</span> <span class="fu">drop</span> (<span class="fu">length</span> old) rest]</code></pre>
<p>We are now ready to implement the function <code>apply</code>, which performs rule application. This function takes a rule and a string and produces all strings that can be derived from the given string using the given rule exactly once.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">apply ::</span> <span class="dt">Rule</span> <span class="ot">-&gt;</span> <span class="dt">Str</span> <span class="ot">-&gt;</span> [<span class="dt">Str</span>]
apply <span class="dt">R1</span> str        <span class="fu">|</span> <span class="fu">last</span> str <span class="fu">==</span> <span class="dt">I</span> <span class="fu">=</span> [str <span class="fu">++</span> [<span class="dt">U</span>]]
apply <span class="dt">R2</span> (<span class="dt">M</span> <span class="fu">:</span> <span class="fu">tail</span>)                 <span class="fu">=</span> [<span class="dt">M</span> <span class="fu">:</span> <span class="fu">tail</span> <span class="fu">++</span> <span class="fu">tail</span>]
apply <span class="dt">R3</span> str                        <span class="fu">=</span> replace [<span class="dt">I</span>,<span class="dt">I</span>,<span class="dt">I</span>] [<span class="dt">U</span>] str
apply <span class="dt">R4</span> str                        <span class="fu">=</span> replace [<span class="dt">U</span>,<span class="dt">U</span>]   []  str
apply _  _                          <span class="fu">=</span> []</code></pre>
<h3 id="derivation-trees">Derivation trees</h3>
<p>Now we want to build derivation trees. A derivation tree for a string <code>str</code> has the following properties:</p>
<ul>
<li>The root is labeled with <code>str</code>.</li>
<li>The subtrees of the root are the derivation trees for the strings that can be generated from <code>str</code> by a single rule application.</li>
<li>The edges from the root to its subtrees are marked with the respective rules that are applied.</li>
</ul>
<p>We first define types for representing derivation trees:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">DTree</span> <span class="fu">=</span> <span class="dt">DTree</span> <span class="dt">Str</span> [<span class="dt">DSub</span>]

<span class="kw">data</span> <span class="dt">DSub</span>  <span class="fu">=</span> <span class="dt">DSub</span> <span class="dt">Rule</span> <span class="dt">DTree</span></code></pre>
<p>Now we define the function <code>dTree</code> that turns a string into its derivation tree:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">dTree ::</span> <span class="dt">Str</span> <span class="ot">-&gt;</span> <span class="dt">DTree</span>
dTree str <span class="fu">=</span> <span class="dt">DTree</span> str [<span class="dt">DSub</span> rule subtree <span class="fu">|</span>
                          rule <span class="ot">&lt;-</span> rules,
                          subStr <span class="ot">&lt;-</span> apply rule str,
                          <span class="kw">let</span> subtree <span class="fu">=</span> dTree subStr]</code></pre>
<h3 id="derivations">Derivations</h3>
<p>A derivation is a sequence of strings with rules between them such that each rule takes the string before it to the string after it. We define types for representing derivations:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">Deriv</span> <span class="fu">=</span> <span class="dt">Deriv</span> [<span class="dt">DStep</span>] <span class="dt">Str</span>

<span class="kw">data</span> <span class="dt">DStep</span> <span class="fu">=</span> <span class="dt">DStep</span> <span class="dt">Str</span> <span class="dt">Rule</span>

<span class="kw">instance</span> <span class="kw">Show</span> <span class="dt">Deriv</span> <span class="kw">where</span>

    <span class="fu">show</span> (<span class="dt">Deriv</span> steps goal) <span class="fu">=</span> <span class="st">&quot;        &quot;</span>           <span class="fu">++</span>
                              <span class="fu">concatMap</span> <span class="fu">show</span> steps <span class="fu">++</span>
                              <span class="fu">show</span> goal            <span class="fu">++</span>
                              <span class="st">&quot;\n&quot;</span>

    <span class="fu">showList</span> derivs
        <span class="fu">=</span> (<span class="fu">concatMap</span> ((<span class="fu">++</span> <span class="st">&quot;\n&quot;</span>) <span class="fu">.</span> <span class="fu">show</span>) derivs <span class="fu">++</span>)

<span class="kw">instance</span> <span class="kw">Show</span> <span class="dt">DStep</span> <span class="kw">where</span>

    <span class="fu">show</span> (<span class="dt">DStep</span> origin rule) <span class="fu">=</span> <span class="fu">show</span> origin <span class="fu">++</span>
                               <span class="st">&quot;\n-&gt; (&quot;</span>    <span class="fu">++</span>
                               <span class="fu">show</span> rule   <span class="fu">++</span>
                               <span class="st">&quot;) &quot;</span></code></pre>
<p>Now we implement a function <code>derivs</code> that converts a derivation tree into the list of all derivations that start with the tree’s root label. The function <code>derivs</code> traverses the tree in breadth-first order.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">derivs ::</span> <span class="dt">DTree</span> <span class="ot">-&gt;</span> [<span class="dt">Deriv</span>]
derivs tree <span class="fu">=</span> worker [([],tree)] <span class="kw">where</span>

<span class="ot">    worker ::</span> [([<span class="dt">DStep</span>],<span class="dt">DTree</span>)] <span class="ot">-&gt;</span> [<span class="dt">Deriv</span>]
    worker tasks <span class="fu">=</span> rootDerivs tasks        <span class="fu">++</span>
                   worker (subtasks tasks)

<span class="ot">    rootDerivs ::</span> [([<span class="dt">DStep</span>],<span class="dt">DTree</span>)] <span class="ot">-&gt;</span> [<span class="dt">Deriv</span>]
    rootDerivs tasks <span class="fu">=</span> [<span class="dt">Deriv</span> (<span class="fu">reverse</span> revSteps) root <span class="fu">|</span>
                           (revSteps,<span class="dt">DTree</span> root _) <span class="ot">&lt;-</span> tasks]

<span class="ot">    subtasks ::</span> [([<span class="dt">DStep</span>],<span class="dt">DTree</span>)] <span class="ot">-&gt;</span> [([<span class="dt">DStep</span>],<span class="dt">DTree</span>)]
    subtasks tasks <span class="fu">=</span> [(<span class="dt">DStep</span> root rule <span class="fu">:</span> revSteps,subtree) <span class="fu">|</span>
                         (revSteps,<span class="dt">DTree</span> root subs) <span class="ot">&lt;-</span> tasks,
                         <span class="dt">DSub</span> rule subtree          <span class="ot">&lt;-</span> subs]</code></pre>
<p>Finally, we implement the function <code>derivations</code> which takes two strings and returns the list of those derivations that turn the first string into the second:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">derivations ::</span> <span class="dt">Str</span> <span class="ot">-&gt;</span> <span class="dt">Str</span> <span class="ot">-&gt;</span> [<span class="dt">Deriv</span>]
derivations start end
    <span class="fu">=</span> [deriv <span class="fu">|</span> deriv<span class="fu">@</span>(<span class="dt">Deriv</span> _ goal) <span class="ot">&lt;-</span> derivs (dTree start),
               goal <span class="fu">==</span> end]</code></pre>
<p>You may want to enter</p>
<p style="text-align:center;"><code>derivations [M,I] [M,U,I]</code></p>
<p>at the GHCi prompt to see the <code>derivations</code> function in action. You can also enter</p>
<p style="text-align:center;"><code>derivations [M,I] [M,U]</code></p>
<p>to get an idea about the solution to the MU puzzle.</p>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/douglas-hofstadter/'>Douglas Hofstadter</a>, <a href='http://jeltsch.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://jeltsch.wordpress.com/tag/godel-escher-bach-book/'>Gödel, Escher, Bach (book)</a>, <a href='http://jeltsch.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://jeltsch.wordpress.com/tag/james-chapman/'>James Chapman</a>, <a href='http://jeltsch.wordpress.com/tag/literate-programming/'>literate programming</a>, <a href='http://jeltsch.wordpress.com/tag/mu-puzzle/'>MU puzzle</a>, <a href='http://jeltsch.wordpress.com/tag/string-rewriting/'>string rewriting</a>, <a href='http://jeltsch.wordpress.com/tag/theory-lunch/'>Theory Lunch</a>, <a href='http://jeltsch.wordpress.com/tag/ttu-kuberneetika-instituut/'>TTÜ Küberneetika Instituut</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/582/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/582/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=582&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2013/04/18/miu-in-haskell/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
		<item>
		<title>The Constraint kind</title>
		<link>http://jeltsch.wordpress.com/2013/02/14/the-constraint-kind/</link>
		<comments>http://jeltsch.wordpress.com/2013/02/14/the-constraint-kind/#comments</comments>
		<pubDate>Thu, 14 Feb 2013 16:19:39 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[Constraint (kind)]]></category>
		<category><![CDATA[containers (Haskell package)]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[GHC]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[kind]]></category>
		<category><![CDATA[literate programming]]></category>
		<category><![CDATA[monad]]></category>
		<category><![CDATA[multi-parameter type class]]></category>
		<category><![CDATA[Theory Lunch]]></category>
		<category><![CDATA[TTÜ Küberneetika Instituut]]></category>
		<category><![CDATA[type class]]></category>
		<category><![CDATA[type family]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=567</guid>
		<description><![CDATA[A recent language extension of the Glasgow Haskell Compiler (GHC) is the Constraint kind. In this blog post, I will show some examples of how this new feature can be used. This is a write-up of my Theory Lunch talk from 7 February 2013. The source of this article is a literate Haskell file, which you can [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=567&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>A recent language extension of the Glasgow Haskell Compiler (GHC) is the <code>Constraint</code> kind. In this blog post, I will show some examples of how this new feature can be used. This is a write-up of my <a href="http://theorylunch.wordpress.com/" title="Theory Lunch">Theory Lunch</a> talk from 7 February 2013. The source of this article is a literate Haskell file, which you can <a href="http://darcs.wolfgang.jeltsch.info/blog/2013/02/14/the-constraint-kind.lhs" title="The Constraint kind">download</a> and load into GHCi.<span id="more-567"></span></p>
<h2 id="prerequisites">Prerequisites</h2>
<p>The example code in this article needs support for the <code>Constraint</code> kind, of course. So we have to enable the appropriate language extension (which is surprisingly called <code>ConstraintKinds</code> instead of <code>ConstraintKind</code>). Furthermore, we want to make use of type families. All in all, this leads to the following <code>LANGUAGE</code> pragma:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE ConstraintKinds, TypeFamilies #-}</span></code></pre>
<p>We will define our own version of the <code>Monad</code> class. Therefore, we have to hide the <code>Monad</code> class from the Prelude:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Prelude</span> <span class="kw">hiding</span> (<span class="kw">Monad</span> (<span class="fu">..</span>))</code></pre>
<p>We will need the module <code>Data.Set</code> from the <code>containers</code> package for some example code:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Data.Set</span></code></pre>
<p>Last, but not least, we have to import the kind <code>Constraint</code>:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">GHC.Exts</span> (<span class="dt">Constraint</span>)</code></pre>
<h2 id="the-general-picture">The general picture</h2>
<p>Originally, classes and contexts were not first-class citizens in Haskell. The introduction of the <code>Constraint</code> kind has changed this. Classes and contexts can now be used as parameters of types, for example. This is because they are now types themselves.</p>
<p>However, classes and contexts are still not types in the strict sense. There are still no values of type <code>Eq</code> or <code>Eq Integer</code>, for example. As I have explained in <a href="http://jeltsch.wordpress.com/2013/02/09/some-interesting-features-of-haskells-type-system.lhs" title="Some interesting features of Haskell’s type system">my previous post</a>, Haskell’s notion of type is more general than the usual one. In particular, functions on types are types themselves. However, they are not types of kind <code>*</code>. The same holds for classes and contexts. They are not types of kind <code>*</code>, but they are types of some other kinds, so that they can generally be used in places where types can be used.</p>
<p>The new kind <code>Constraint</code>, which is exported by <code>GHC.Exts</code>, is the kind of all contexts. Classes and contexts are now handled as follows:</p>
<ul>
<li>
<p>Each class with parameters of kinds <code>k_1</code> through <code>k_n</code> is a type of kind <code>k_1 -&gt; k_n -&gt; Constraint</code>.</p>
</li>
<li>
<p>Each tuple type <code>(t_1, ..., t_n)</code> where <code>t_1</code> through <code>t_n</code> are of kind <code>Constraint</code> is also of kind <code>Constraint</code> and denotes the conjunction of <code>t_1</code> through <code>t_n</code>. As a corner case, the nullary tuple type <code>()</code> is also of type <code>Constraint</code> and denotes the constraint that is always true.</p>
</li>
<li>
<p>A context can be any type of kind <code>Constraint</code>.</p>
</li>
</ul>
<p>These rules guarantee that classes and contexts can be used as before. For example, <code>(Read val, Show val)</code> is still a context, because <code>Read</code> and <code>Show</code> are types of kind <code>* -&gt; Constraint</code>, so <code>Read val</code> and <code>Show val</code> are types of kind <code>Constraint</code>, and therefore <code>(Read val, Show val)</code> is a type of kind <code>Constraint</code>.</p>
<p>However, classes and constraints can be used in new ways now. Here are some examples:</p>
<ul>
<li>
<p>Classes can be partially applied, and the results can be used like classes again.</p>
</li>
<li>
<p>Classes, partially applied classes, and contexts can be parameters of types and instances of classes.</p>
</li>
<li>
<p>Aliases of classes, partially applied classes, and contexts can be defined using <code class="sourceCode haskell"><span class="kw">type</span></code> declarations.</p>
</li>
<li>
<p>Families of classes, partially applied classes, and contexts can be defined using type synonym families.</p>
</li>
</ul>
<p>In the remainder of this article, I will illustrate the last two of these points.</p>
<h2 id="context-aliases">Context aliases</h2>
<p>Sometimes, the same conjunction of several contexts appears in multiple types. In such cases, it can become cumbersome to always write these conjunctions explicitly. For example, there might be several functions in a library that deal with values that can be turned into strings and generated from strings. In this case, the types of these functions will typically have a context that contains constraints <code>Show val</code> and <code>Read val</code>. With the <code>Constraint</code> kind, we can define context aliases <code>Text val</code> as follows:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">type</span> <span class="dt">Text</span> val <span class="fu">=</span> (<span class="kw">Show</span> val, <span class="kw">Read</span> val)</code></pre>
<p>Instead of <code>Show val, Read val</code>, we can now simply write <code>Text val</code> in contexts.</p>
<p>A few years ago, there was an attempt to implement support for context aliases (often called class aliases) in GHC. With the <code>Constraint</code> kind, this is now obsolete, as context aliases are now just a special kind of type aliases.</p>
<h2 id="context-families">Context families</h2>
<p>We will illustrate the use of context families by defining a generalized version of the <code>Monad</code> class.</p>
<p>The actual definition of a monad from category theory says that a monad on a category <em>𝒞</em> consists of an endofunctor on <em>𝒞</em> and some natural transformations. In Haskell, however, a monad is defined to be an instance of the <code>Monad</code> class, which contains the two methods <code>return</code> and <code>(&gt;&gt;=)</code>. Haskell monads are monads on the category <strong>Hask</strong>, the category of kind-<code>*</code> types and functions.</p>
<p>There are monads in the category theory sense that are almost monads in the Haskell sense, but not quite. One example is the monad behind Haskell’s <code>Set</code> type. There are reasonable implementations of <code>return</code> and <code>(&gt;&gt;=)</code> for <code>Set</code>:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">setReturn ::</span> el <span class="ot">-&gt;</span> <span class="dt">Set</span> el
setReturn <span class="fu">=</span> singleton

<span class="ot">setBind ::</span> (<span class="kw">Ord</span> el, <span class="kw">Ord</span> el&#039;) <span class="ot">=&gt;</span>
           <span class="dt">Set</span> el <span class="ot">-&gt;</span> (el <span class="ot">-&gt;</span> <span class="dt">Set</span> el&#039;) <span class="ot">-&gt;</span> <span class="dt">Set</span> el&#039;
setBind set1 gen2 <span class="fu">=</span> unions (Prelude.map gen2 (toList set1))</code></pre>
<p>The problem is that the type of <code>setBind</code> is too restrictive, as it restricts the choice of element types by a context, whereas there is no such restriction in the type of <code>(&gt;&gt;=)</code>. The reason for the restriction on element types is that the <code>Set</code> monad is not a monad on the category <strong>Hask</strong>, but on the full subcategory of <strong>Hask</strong> whose objects are the instances of <code>Ord</code>.</p>
<p>Using context families, we can generalize the <code>Monad</code> class such that restrictions on the type parameters of <code>Monad</code> instances become possible. We introduce a type synonym family <code>Object</code> such that <code>Object mon val</code> is the constraint that the parameter <code>val</code> must fulfill when working with the <code>Monad</code> instance <code>mon</code>. We provide a default definition for <code>Object</code> that does not restrict monad parameters. Finally, we change the types of <code>return</code> and <code>(&gt;&gt;=)</code> such that they restrict their <code>Monad</code> instance parameters accordingly. The new declaration of the <code>Monad</code> class is as follows:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="kw">Monad</span> mon <span class="kw">where</span>

    <span class="kw">type</span> <span class="dt">Object</span> mon<span class="ot"> val ::</span> <span class="dt">Constraint</span>
    <span class="kw">type</span> <span class="dt">Object</span> mon val <span class="fu">=</span> ()

<span class="ot">    return ::</span> <span class="dt">Object</span> mon val <span class="ot">=&gt;</span>
              val <span class="ot">-&gt;</span> mon val

<span class="ot">    (&gt;&gt;=)  ::</span> (<span class="dt">Object</span> mon val, <span class="dt">Object</span> mon val&#039;) <span class="ot">=&gt;</span>
              mon val <span class="ot">-&gt;</span> (val <span class="ot">-&gt;</span> mon val&#039;) <span class="ot">-&gt;</span> mon val&#039;</code></pre>
<p>We can now make <code>Set</code> an instance of <code>Monad</code>:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Monad</span> <span class="dt">Set</span> <span class="kw">where</span>

    <span class="kw">type</span> <span class="dt">Object</span> <span class="dt">Set</span> el <span class="fu">=</span> <span class="kw">Ord</span> el

    <span class="fu">return</span> <span class="fu">=</span> setReturn

    (<span class="fu">&gt;&gt;=</span>) <span class="fu">=</span> setBind</code></pre>
<p>We can make every instance of the original <code>Monad</code> class an instance of our new <code>Monad</code> class. Because of the default definition of <code>Object</code>, we do not need to define <code>Object</code> in these cases. So the <code class="sourceCode haskell"><span class="kw">instance</span></code> declarations can look exactly like those for the original <code>Monad</code> class. Here is an example for the <code>[]</code> type:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Monad</span> [] <span class="kw">where</span>

    <span class="fu">return</span> x <span class="fu">=</span> [x]

    (<span class="fu">&gt;&gt;=</span>) <span class="fu">=</span> <span class="fu">flip</span> <span class="fu">concatMap</span></code></pre>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/category-theory/'>category theory</a>, <a href='http://jeltsch.wordpress.com/tag/constraint-kind/'>Constraint (kind)</a>, <a href='http://jeltsch.wordpress.com/tag/containers-haskell-package/'>containers (Haskell package)</a>, <a href='http://jeltsch.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://jeltsch.wordpress.com/tag/ghc/'>GHC</a>, <a href='http://jeltsch.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://jeltsch.wordpress.com/tag/kind/'>kind</a>, <a href='http://jeltsch.wordpress.com/tag/literate-programming/'>literate programming</a>, <a href='http://jeltsch.wordpress.com/tag/monad/'>monad</a>, <a href='http://jeltsch.wordpress.com/tag/multi-parameter-type-class/'>multi-parameter type class</a>, <a href='http://jeltsch.wordpress.com/tag/theory-lunch/'>Theory Lunch</a>, <a href='http://jeltsch.wordpress.com/tag/ttu-kuberneetika-instituut/'>TTÜ Küberneetika Instituut</a>, <a href='http://jeltsch.wordpress.com/tag/type-class/'>type class</a>, <a href='http://jeltsch.wordpress.com/tag/type-family/'>type family</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/567/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/567/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=567&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2013/02/14/the-constraint-kind/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
		<item>
		<title>Some interesting features of Haskell’s type system</title>
		<link>http://jeltsch.wordpress.com/2013/02/09/some-interesting-features-of-haskells-type-system/</link>
		<comments>http://jeltsch.wordpress.com/2013/02/09/some-interesting-features-of-haskells-type-system/#comments</comments>
		<pubDate>Sat, 09 Feb 2013 21:47:11 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[containers (Haskell package)]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[GHC]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[kind]]></category>
		<category><![CDATA[literate programming]]></category>
		<category><![CDATA[Markdown]]></category>
		<category><![CDATA[multi-parameter type class]]></category>
		<category><![CDATA[natural-numbers (Haskell package)]]></category>
		<category><![CDATA[Pandoc]]></category>
		<category><![CDATA[parametricity]]></category>
		<category><![CDATA[Stream (Haskell package)]]></category>
		<category><![CDATA[Theory Lunch]]></category>
		<category><![CDATA[TTÜ Küberneetika Instituut]]></category>
		<category><![CDATA[type class]]></category>
		<category><![CDATA[type family]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=545</guid>
		<description><![CDATA[One of the most important ingredients of Haskell is its type system. Standard Haskell already provides a lot of useful mechanisms for having things checked at compile time, and the language extensions provided by the Glasgow Haskell Compiler (GHC) improve heavily on this. In this article, I will present several of Haskell’s type system features. [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=545&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>One of the most important ingredients of Haskell is its type system. <a href="http://www.haskell.org/onlinereport/haskell2010/" title="Haskell 2010 Language Report">Standard Haskell</a> already provides a lot of useful mechanisms for having things checked at compile time, and the language extensions provided by the <a href="http://haskell.org/ghc/" title="Glasgow Haskell Compiler">Glasgow Haskell Compiler (GHC)</a> improve heavily on this.</p>
<p>In this article, I will present several of Haskell’s type system features. Some of them belong to the standard, others are only available as extensions. This is a write-up of a talk I gave on 31 January 2013 during the <a href="http://theorylunch.wordpress.com/" title="Theory Lunch">Theory Lunch</a> of the <a href="http://www.ioc.ee/wiki/doku.php?id=en:start" title="Institute of Cybernetics">Institute of Cybernetics</a>. This talk provided the basics for another Theory Lunch talk, which was about the <code>Constraint</code> kind.<span id="more-545"></span></p>
<p>This whole article was written as a literate Haskell file with ordinary text written in <a href="http://daringfireball.net/projects/markdown/" title="Markdown">Markdown</a>. You can download <a href="http://darcs.wolfgang.jeltsch.info/blog/2013/02/09/some-interesting-features-of-haskells-type-system.lhs" title="Some interesting features of Haskell’s type system">this literate Haskell file</a>, read it, and load it into GHCi to play with the code. The HTML for the blog post was generated using <a href="http://johnmacfarlane.net/pandoc/" title="Pandoc">Pandoc</a>.</p>
<h2 id="prerequisites">Prerequisites</h2>
<p>We first enable some language extensions that we will use in this article:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE MultiParamTypeClasses, TypeFamilies #-}</span></code></pre>
<p>We will reimplement some bits of the Prelude for illustration purposes, and we will use functions from other modules whose names clash with those of certain Prelude functions. Therefore, we have to hide parts of the Prelude:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Prelude</span> <span class="kw">hiding</span> (<span class="kw">Eq</span> (<span class="fu">..</span>), <span class="kw">Functor</span> (<span class="fu">..</span>), <span class="fu">lookup</span>, (<span class="fu">!!</span>))</code></pre>
<p>Furthermore, we need some additional modules for example code:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">import</span> <span class="dt">Data.Char</span>
<span class="kw">import</span> <span class="dt">Data.Natural</span>
<span class="kw">import</span> <span class="dt">Data.Stream</span>  <span class="kw">hiding</span> (<span class="fu">map</span>)
<span class="kw">import</span> <span class="dt">Data.Set</span>     <span class="kw">hiding</span> (<span class="fu">map</span>)
<span class="kw">import</span> <span class="dt">Data.IntSet</span>  <span class="kw">hiding</span> (<span class="fu">map</span>)</code></pre>
<p>These imports require the packages <code>Stream</code>, <code>natural-numbers</code>, and <code>containers</code> to be installed.</p>
<h2 id="kinds">Kinds</h2>
<p>Types typically denote sets of values. For example, <code>Integer</code> denotes the set of all integers, <code>Char</code> denotes the set of all characters, and <code>[Bool]</code> denotes the set of all truth value lists.</p>
<p>However, Haskell uses a more general notion of type, which also covers functions on types. So for example, the unapplied list type constructor <code>[]</code> is also considered a type, as is a partial application of the function type constructor like <code>(-&gt;) Integer</code>. Clearly, these types do not contain values.</p>
<p>To distinguish between ordinary types and functions on types, Haskell uses a system of kinds. Kinds are the “types of types”, so to say. A kind is either <code>*</code> or has the form <code>kind1 -&gt; kind2</code>, where <code>kind1</code> and <code>kind2</code> are again kinds. The kind <code>*</code> is the kind of all ordinary types (that is, types that contain values), and a <code>kind1 -&gt; kind2</code> is the kind of all type-level functions from <code>kind1</code> to <code>kind2</code>. Following are some examples of types and their kinds:</p>
<ul>
<li><code>Integer, Char, [Bool], [[Bool]], [val] :: *</code></li>
<li><code>[], Maybe :: * -&gt; *</code></li>
</ul>
<p>Note that in a kind <code>kind1 -&gt; kind2</code>, <code>kind1</code> and <code>kind2</code> can be kinds of function types again. So higher-order types are possible. As a result, type functions with several arguments can be implemented by means of Currying. For example, Haskell’s pair type and function type constructors are kinded as follows:</p>
<ul>
<li><code>(,), (-&gt;) :: * -&gt; * -&gt; *</code></li>
</ul>
<p>Furthermore, we can have type constructors with type function arguments. Take the following generic types of trees and forests as an example:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">data</span>    <span class="dt">Tree</span>   func label <span class="fu">=</span> <span class="dt">Tree</span> label (<span class="dt">Forest</span> func label)

<span class="kw">newtype</span> <span class="dt">Forest</span> func label <span class="fu">=</span> <span class="dt">Forest</span> (func (<span class="dt">Tree</span> func label))</code></pre>
<p>From these types, we can get various more concrete types by partial application:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">type</span> <span class="dt">RoseTree</span>          <span class="fu">=</span> <span class="dt">Tree</span>   []

<span class="kw">type</span> <span class="dt">RoseForest</span>        <span class="fu">=</span> <span class="dt">Forest</span> []

<span class="kw">type</span> <span class="dt">NonEmptyList</span>      <span class="fu">=</span> <span class="dt">Tree</span>   <span class="dt">Maybe</span>

<span class="kw">type</span> <span class="dt">PossiblyEmptyList</span> <span class="fu">=</span> <span class="dt">Forest</span> <span class="dt">Maybe</span>

<span class="kw">type</span> <span class="dt">InfiniteList</span>      <span class="fu">=</span> <span class="dt">Tree</span>   <span class="dt">Identity</span></code></pre>
<p>The <code>Identity</code> type used in the definition of <code>Stream</code> is defined as follows:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">newtype</span> <span class="dt">Identity</span> val <span class="fu">=</span> <span class="dt">Identity</span> val</code></pre>
<p>I also want to mention that if we have a type <code>Event</code> in functional reactive programming, <code>Tree Event</code> is the type of behaviors that change only at discrete times, and <code>Forest Event</code> is the type of event streams.</p>
<h2 id="type-classes">Type classes</h2>
<p>A type class denotes a set of types, which are called the instances of the class. Each class declares a set of methods that its instances have to implement.</p>
<h3 id="simple-type-classes">Simple type classes</h3>
<p>As an example of a type class, let us partially reimplement the <code>Eq</code> class from the Prelude, whose methods are <code>(==)</code> and <code>(/=)</code>:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="kw">Eq</span> val <span class="kw">where</span>

    (<span class="fu">==</span>),<span class="ot"> (/=) ::</span> val <span class="ot">-&gt;</span> val <span class="ot">-&gt;</span> <span class="dt">Bool</span></code></pre>
<p><code>Eq</code> is supposed to cover all types whose values can be checked for equality. Here is an <code class="sourceCode haskell"><span class="kw">instance</span></code> declaration for the <code>Bool</code> type:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Eq</span> <span class="dt">Bool</span> <span class="kw">where</span>

    <span class="kw">False</span> <span class="fu">==</span> bool2 <span class="fu">=</span> <span class="fu">not</span> bool2
    <span class="kw">True</span>  <span class="fu">==</span> bool2 <span class="fu">=</span> bool2

    bool1 <span class="fu">/=</span> bool2 <span class="fu">=</span> <span class="fu">not</span> (bool1 <span class="fu">==</span> bool2)</code></pre>
<h3 id="constructor-classes">Constructor classes</h3>
<p>It is possible to define classes whose instances have a kind other than <code>*</code>. These are sometimes called constructor classes. An example of such a class is the <code>Functor</code> class from the Prelude, whose instances have kind <code>* -&gt; *</code>. Here is a reimplementation:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="kw">Functor</span> func <span class="kw">where</span>

<span class="ot">    fmap ::</span> (val <span class="ot">-&gt;</span> val&#039;) <span class="ot">-&gt;</span> (func val <span class="ot">-&gt;</span> func val&#039;)</code></pre>
<p>Typical instances of <code>Functor</code> are <code>[]</code> and <code>Maybe</code>:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Functor</span> [] <span class="kw">where</span>

    <span class="fu">fmap</span> <span class="fu">=</span> <span class="fu">map</span>

<span class="kw">instance</span> <span class="kw">Functor</span> <span class="dt">Maybe</span> <span class="kw">where</span>

    <span class="fu">fmap</span> _   <span class="kw">Nothing</span>    <span class="fu">=</span> <span class="kw">Nothing</span>
    <span class="fu">fmap</span> fun (<span class="kw">Just</span> val) <span class="fu">=</span> <span class="kw">Just</span> (fun val)</code></pre>
<p>Types <code>Tree func</code> and <code>Forest func</code> can also be made instances of <code>Functor</code>, provided that <code>func</code> is a <code>Functor</code> instance itself.</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Functor</span> func <span class="ot">=&gt;</span> <span class="kw">Functor</span> (<span class="dt">Tree</span> func) <span class="kw">where</span>

    <span class="fu">fmap</span> fun (<span class="dt">Tree</span> root subtrees) <span class="fu">=</span> <span class="dt">Tree</span> (fun root)
                                         (<span class="fu">fmap</span> fun subtrees)

<span class="kw">instance</span> <span class="kw">Functor</span> func <span class="ot">=&gt;</span> <span class="kw">Functor</span> (<span class="dt">Forest</span> func) <span class="kw">where</span>

    <span class="fu">fmap</span> fun (<span class="dt">Forest</span> trees) <span class="fu">=</span> <span class="dt">Forest</span> (<span class="fu">fmap</span> (<span class="fu">fmap</span> fun) trees)</code></pre>
<p>Note that these <code class="sourceCode haskell"><span class="kw">instance</span></code> declarations make the specialized versions of <code>Tree</code> and <code>Forest</code> that we have defined above automatically instances of <code>Functor</code>.</p>
<h3 id="multi-parameter-type-classes">Multi-parameter type classes</h3>
<p>GHC allows classes to have multiple parameters. While single-parameter classes denote sets of types, multi-parameter classes denote relations between types. An example of a class with two parameters is the class that relates types for which there is a conversion function:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="dt">Convertible</span> val val&#039; <span class="kw">where</span>

<span class="ot">    convert ::</span> val <span class="ot">-&gt;</span> val&#039;</code></pre>
<p>We can convert from type <code>Int</code> to type <code>Integer</code>, but also between types <code>Int</code> and <code>Char</code>:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="dt">Convertible</span> <span class="dt">Int</span> <span class="dt">Integer</span> <span class="kw">where</span>

    convert <span class="fu">=</span> <span class="fu">toInteger</span>

<span class="kw">instance</span> <span class="dt">Convertible</span> <span class="dt">Int</span> <span class="dt">Char</span> <span class="kw">where</span>

    convert <span class="fu">=</span> <span class="fu">chr</span>

<span class="kw">instance</span> <span class="dt">Convertible</span> <span class="dt">Char</span> <span class="dt">Int</span> <span class="kw">where</span>

    convert <span class="fu">=</span> <span class="fu">ord</span></code></pre>
<h2 id="type-families">Type families</h2>
<p>Haskell allows us to define new types using <code class="sourceCode haskell"><span class="kw">data</span></code> declarations. An example of such a declaration is the following one, which introduces a type of lists:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">data</span> <span class="dt">List</span> el <span class="fu">=</span> <span class="dt">Nil</span> <span class="fu">|</span> <span class="dt">Cons</span> el (<span class="dt">List</span> el)</code></pre>
<p>Furthermore, we can use <code class="sourceCode haskell"><span class="kw">type</span></code> declarations for defining aliases of existing types. For example, we can use the following <code class="sourceCode haskell"><span class="kw">type</span></code> declaration to define types of functions whose domain and codomain are the same:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">type</span> <span class="dt">Endo</span> val <span class="fu">=</span> val <span class="ot">-&gt;</span> val</code></pre>
<p>Both <code class="sourceCode haskell"><span class="kw">data</span></code> and <code class="sourceCode haskell"><span class="kw">type</span></code> declarations have in common that the types they define are parametric. Informally speaking, this means that the basic structure of the defined types is independent of type parameters. For example, lists are always either empty or pairs of an element and another list, no matter what the element type is. The choice of an <code>el</code> parameter only determines the structure of elements. Likewise, values of a type <code>Endo val</code> are always functions whose domain and codomain are the same. The <code>val</code> parameter just determines the concrete domain and codomain type in use.</p>
<p>There are situations, however, where we want to define type-level functions that yield completely differently structured types for different arguments. This is possible with the type family extension that GHC provides.</p>
<p>There exist two flavors of type families: data families and type synonym families. Data families introduce new types and use the <code class="sourceCode haskell"><span class="kw">data</span></code> keyword, while type synonym families define aliases for types and use the <code class="sourceCode haskell"><span class="kw">type</span></code> keyword. This is analogous to <code class="sourceCode haskell"><span class="kw">data</span></code> and <code class="sourceCode haskell"><span class="kw">type</span></code> declarations, respectively. Type families can be stand-alone or associated. The former variant is analogous to top-level functions, while the latter is analogous to class methods. We will only deal with the latter in this post.</p>
<h3 id="data-families">Data families</h3>
<p>As an example of a data family, we define a type of total maps, that is, maps that assign values to every value of a chosen key type. Essential to our definition is that different key types lead to differently structured maps. We declare a class of key types, which contains the data family for total maps:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="dt">Key</span> key <span class="kw">where</span>

    <span class="kw">data</span> <span class="dt">TotalMap</span><span class="ot"> key ::</span> <span class="fu">*</span> <span class="ot">-&gt;</span> <span class="fu">*</span>

<span class="ot">    lookup ::</span> key <span class="ot">-&gt;</span> <span class="dt">TotalMap</span> key val <span class="ot">-&gt;</span> val</code></pre>
<p>Let us now give an <code class="sourceCode haskell"><span class="kw">instance</span></code> declaration for <code>Bool</code>. Total maps with boolean keys are essentially pairs of values, consisting of one value for the <code>False</code> key and one value for the <code>True</code> key. Our <code class="sourceCode haskell"><span class="kw">instance</span></code> declaration reflects this:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="dt">Key</span> <span class="dt">Bool</span> <span class="kw">where</span>

    <span class="kw">data</span> <span class="dt">TotalMap</span> <span class="dt">Bool</span> val <span class="fu">=</span> <span class="dt">BoolMap</span> val val

    <span class="fu">lookup</span> <span class="kw">False</span> (<span class="dt">BoolMap</span> falseVal _)       <span class="fu">=</span> falseVal
    <span class="fu">lookup</span> <span class="kw">True</span>  (<span class="dt">BoolMap</span> _        trueVal) <span class="fu">=</span> trueVal</code></pre>
<p>Total maps whose keys are natural numbers correspond to infinite lists, that is, streams of values:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="dt">Key</span> <span class="dt">Natural</span> <span class="kw">where</span>

    <span class="kw">data</span> <span class="dt">TotalMap</span> <span class="dt">Natural</span> val <span class="fu">=</span> <span class="dt">NaturalMap</span> (<span class="dt">Stream</span> val)

    <span class="fu">lookup</span> nat (<span class="dt">NaturalMap</span> str) <span class="fu">=</span> str <span class="fu">!!</span> <span class="fu">fromIntegral</span> nat</code></pre>
<p>More advanced things are possible. For example, pairs of keys can again serve as keys. A total map of a type <code>TotalMap (key1,key2) val</code> corresponds to a function of type <code>(key1,key2) -&gt; val</code>, which in turn corresponds to a function of type <code>key1 -&gt; key2 -&gt; val</code>. This suggests how to implement total maps with pair keys:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> (<span class="dt">Key</span> key1, <span class="dt">Key</span> key2) <span class="ot">=&gt;</span> <span class="dt">Key</span> (key1,key2) <span class="kw">where</span>

    <span class="kw">data</span> <span class="dt">TotalMap</span> (key1,key2) val
        <span class="fu">=</span> <span class="dt">PairMap</span> (<span class="dt">TotalMap</span> key1 (<span class="dt">TotalMap</span> key2 val))

    <span class="fu">lookup</span> (key1,key2) (<span class="dt">PairMap</span> curriedMap)
        <span class="fu">=</span> <span class="fu">lookup</span> key2 (<span class="fu">lookup</span> key1 curriedMap)</code></pre>
<h3 id="type-synonym-families">Type synonym families</h3>
<p>Let us now look at an example of a type synonym family. We define a class of collection types where a collection is basically anything that contains elements. Here are two examples of collection types:</p>
<ul>
<li><code>Set el</code> for any type <code>el</code> that is an instance of <code>Ord</code></li>
<li><code>IntSet</code></li>
</ul>
<p>Our class contains a type synonym family that tells for every collection type what the corresponding type of collection elements is. The <code class="sourceCode haskell"><span class="kw">class</span></code> declaration is as follows:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">class</span> <span class="dt">Collection</span> coll <span class="kw">where</span>

    <span class="kw">type</span> <span class="dt">Element</span><span class="ot"> coll ::</span> <span class="fu">*</span>

<span class="ot">    member ::</span> <span class="dt">Element</span> coll <span class="ot">-&gt;</span> coll <span class="ot">-&gt;</span> <span class="dt">Bool</span></code></pre>
<p>Now we can form <code class="sourceCode haskell"><span class="kw">instance</span></code> declarations for the above example collection types:</p>
<pre class="sourceCode literate haskell"><code class="sourceCode haskell"><span class="kw">instance</span> <span class="kw">Ord</span> el <span class="ot">=&gt;</span> <span class="dt">Collection</span> (<span class="dt">Set</span> el) <span class="kw">where</span>

    <span class="kw">type</span> <span class="dt">Element</span> (<span class="dt">Set</span> el) <span class="fu">=</span> el

    member <span class="fu">=</span> Data.Set.member

<span class="kw">instance</span> <span class="dt">Collection</span> <span class="dt">IntSet</span> <span class="kw">where</span>

    <span class="kw">type</span> <span class="dt">Element</span> <span class="dt">IntSet</span> <span class="fu">=</span> <span class="dt">Int</span>

    member <span class="fu">=</span> Data.IntSet.member</code></pre>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/containers-haskell-package/'>containers (Haskell package)</a>, <a href='http://jeltsch.wordpress.com/tag/frp/'>FRP</a>, <a href='http://jeltsch.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://jeltsch.wordpress.com/tag/ghc/'>GHC</a>, <a href='http://jeltsch.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://jeltsch.wordpress.com/tag/kind/'>kind</a>, <a href='http://jeltsch.wordpress.com/tag/literate-programming/'>literate programming</a>, <a href='http://jeltsch.wordpress.com/tag/markdown/'>Markdown</a>, <a href='http://jeltsch.wordpress.com/tag/multi-parameter-type-class/'>multi-parameter type class</a>, <a href='http://jeltsch.wordpress.com/tag/natural-numbers-haskell-package/'>natural-numbers (Haskell package)</a>, <a href='http://jeltsch.wordpress.com/tag/pandoc/'>Pandoc</a>, <a href='http://jeltsch.wordpress.com/tag/parametricity/'>parametricity</a>, <a href='http://jeltsch.wordpress.com/tag/stream-haskell-package/'>Stream (Haskell package)</a>, <a href='http://jeltsch.wordpress.com/tag/theory-lunch/'>Theory Lunch</a>, <a href='http://jeltsch.wordpress.com/tag/ttu-kuberneetika-instituut/'>TTÜ Küberneetika Instituut</a>, <a href='http://jeltsch.wordpress.com/tag/type-class/'>type class</a>, <a href='http://jeltsch.wordpress.com/tag/type-family/'>type family</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/545/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=545&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2013/02/09/some-interesting-features-of-haskells-type-system/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
		<item>
		<title>Three talks about ideal monads</title>
		<link>http://jeltsch.wordpress.com/2013/01/02/three-talks-about-ideal-monads/</link>
		<comments>http://jeltsch.wordpress.com/2013/01/02/three-talks-about-ideal-monads/#comments</comments>
		<pubDate>Wed, 02 Jan 2013 20:23:39 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[ideal monad]]></category>
		<category><![CDATA[monad]]></category>
		<category><![CDATA[talk]]></category>
		<category><![CDATA[Theory Lunch]]></category>
		<category><![CDATA[TTÜ Küberneetika Instituut]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=513</guid>
		<description><![CDATA[Two months ago, we started the theory lunch meetings at the Institute of Cybernetics. In these meetings, we have lunch together and discuss all kinds of interesting things related to theoretical computer science. We also started the Theory Lunch blog, where an article is posted for every lunch session. I used three of the lunch [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=513&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Two months ago, we started the theory lunch meetings at the Institute of Cybernetics. In these meetings, we have lunch together and discuss all kinds of interesting things related to theoretical computer science. We also started the <a href="http://theorylunch.wordpress.com/" title="Theory Lunch">Theory Lunch blog</a>, where an article is posted for every lunch session. I used three of the lunch meetings to talk about ideal monads, and published summaries of my talks in the following articles:<span id="more-513"></span></p>
<ul>
<li><a title="A short recap of monads" href="http://theorylunch.wordpress.com/2012/11/01/a-short-recap-of-monads/"><em>A short recap of monads</em></a></li>
<li><a href="http://theorylunch.wordpress.com/2012/11/08/an-introduction-to-ideal-monads/" title="An introduction to ideal monads"><em>An introduction to ideal monads</em></a></li>
<li><a href="http://theorylunch.wordpress.com/2012/11/22/what-is-the-correct-definition-of-ideal-monads/" title="What is the correct definition of ideal monads?"><em>What is the correct definition of ideal monads?</em></a></li>
</ul>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/category-theory/'>category theory</a>, <a href='http://jeltsch.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://jeltsch.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://jeltsch.wordpress.com/tag/ideal-monad/'>ideal monad</a>, <a href='http://jeltsch.wordpress.com/tag/monad/'>monad</a>, <a href='http://jeltsch.wordpress.com/tag/talk/'>talk</a>, <a href='http://jeltsch.wordpress.com/tag/theory-lunch/'>Theory Lunch</a>, <a href='http://jeltsch.wordpress.com/tag/ttu-kuberneetika-instituut/'>TTÜ Küberneetika Instituut</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/513/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/513/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=513&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2013/01/02/three-talks-about-ideal-monads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
		<item>
		<title>New paper about a generalization of FRP and causality in categorical models</title>
		<link>http://jeltsch.wordpress.com/2012/11/14/new-paper-about-a-generalization-of-frp-and-causality-in-categorical-models/</link>
		<comments>http://jeltsch.wordpress.com/2012/11/14/new-paper-about-a-generalization-of-frp-and-causality-in-categorical-models/#comments</comments>
		<pubDate>Wed, 14 Nov 2012 16:07:14 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[categorical logic]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[causality]]></category>
		<category><![CDATA[Curry–Howard correspondence]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[intuitionistic logic]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[LTL]]></category>
		<category><![CDATA[modal logic]]></category>
		<category><![CDATA[PLPV]]></category>
		<category><![CDATA[publication]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[talk]]></category>
		<category><![CDATA[temporal logic]]></category>
		<category><![CDATA[TTÜ Küberneetika Instituut]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=480</guid>
		<description><![CDATA[Yesterday I finished my new paper Temporal Logic with “Until”, Functional Reactive Programming with Processes, and Concrete Process Categories, which will appear in the proceedings of PLPV&#160;’13 and is also available online. I have already given two talks on topics of this paper, one at the Joint Estonian–Latvian Theory Days at Medzābaki and another one [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=480&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Yesterday I finished my new paper <em>Temporal Logic with “Until”, Functional Reactive Programming with Processes, and Concrete Process Categories</em>, which will appear in the proceedings of <a href="http://plpv.tcs.ifi.lmu.de/" title="PLPV 2013">PLPV&nbsp;’13</a> and is also <a href="http://www.ioc.ee/~wolfgang/research/plpv-2013-paper.pdf" title="Temporal Logic with “Until”, Functional Reactive Programming with Processes, and Concrete Process Categories">available online</a>. I have already given two talks on topics of this paper, one <a href="http://home.lu.lv/~df/tdays-medzabaki/slides/slides-jeltsch.pdf" title="Expressing Causality in Categorical Models of Functional Reactive Programming">at the Joint Estonian–Latvian Theory Days at Medzābaki</a> and another one <a href="http://cs.ioc.ee/~tarmo/tsem12/jeltsch0410-slides.pdf" title="Concrete Process Categories">at the Theory Seminar of the Institute of Cybernetics</a>.<span id="more-480"></span></p>
<p>The paper covers two topics:
<dl>
<dt>An FRP analog of “until” proofs</dt>
<dd>Temporal logic and FRP are connected via a Curry–Howard correspondence. Thereby the “always” modality corresponds to the type constructor for behaviors, and the “eventually” modality corresponds to the type constructor for events. However there are more temporal operators. One example is the “until” operator from <a href="http://en.wikipedia.org/wiki/Linear_temporal_logic" title="Linear temporal logic">LTL</a>. The paper shows that a proof of an “until” proposition can be regarded as an FRP value that consists of a finite time-varying value and a terminal event. I call such a value a process. It has turned out that processes are a really useful concept for reactive programming, in particular, when they are combined with recursion. The paper gives several examples of their use.</dd>
<dt>Causality in categorical models of FRP</dt>
<dd>In Section&nbsp;2 of <a href="http://jeltsch.wordpress.com/2012/10/01/paper-on-categorical-models-of-temporal-logic-and-frp-published/" title="Paper on categorical models of temporal logic and FRP published">my MFPS paper</a>, I presented a rather simple categorical semantics for temporal logic and FRP, which directly expresses time-dependence of trueness in temporal logic and of type inhabitance in FRP. However this semantics also models noncausal FRP operations, which actually cannot occur in real life. The new paper presents an improved version of the simple categorical semantics that takes causality into account. Its key idea is to deal with the time-dependent knowledge about values instead of the values themselves.</dd>
</dl>
<p>Happy reading!</p>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/categorical-logic/'>categorical logic</a>, <a href='http://jeltsch.wordpress.com/tag/category-theory/'>category theory</a>, <a href='http://jeltsch.wordpress.com/tag/causality/'>causality</a>, <a href='http://jeltsch.wordpress.com/tag/curry-howard-correspondence/'>Curry–Howard correspondence</a>, <a href='http://jeltsch.wordpress.com/tag/frp/'>FRP</a>, <a href='http://jeltsch.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://jeltsch.wordpress.com/tag/intuitionistic-logic/'>intuitionistic logic</a>, <a href='http://jeltsch.wordpress.com/tag/logic/'>logic</a>, <a href='http://jeltsch.wordpress.com/tag/ltl/'>LTL</a>, <a href='http://jeltsch.wordpress.com/tag/modal-logic/'>modal logic</a>, <a href='http://jeltsch.wordpress.com/tag/plpv/'>PLPV</a>, <a href='http://jeltsch.wordpress.com/tag/publication/'>publication</a>, <a href='http://jeltsch.wordpress.com/tag/semantics/'>semantics</a>, <a href='http://jeltsch.wordpress.com/tag/talk/'>talk</a>, <a href='http://jeltsch.wordpress.com/tag/temporal-logic/'>temporal logic</a>, <a href='http://jeltsch.wordpress.com/tag/ttu-kuberneetika-instituut/'>TTÜ Küberneetika Instituut</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/480/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/480/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=480&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2012/11/14/new-paper-about-a-generalization-of-frp-and-causality-in-categorical-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
		<item>
		<title>Paper on categorical models of temporal logic and FRP published</title>
		<link>http://jeltsch.wordpress.com/2012/10/01/paper-on-categorical-models-of-temporal-logic-and-frp-published/</link>
		<comments>http://jeltsch.wordpress.com/2012/10/01/paper-on-categorical-models-of-temporal-logic-and-frp-published/#comments</comments>
		<pubDate>Mon, 01 Oct 2012 11:38:22 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[categorical logic]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[Curry–Howard correspondence]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[intuitionistic logic]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[LTL]]></category>
		<category><![CDATA[MFPS]]></category>
		<category><![CDATA[modal logic]]></category>
		<category><![CDATA[publication]]></category>
		<category><![CDATA[S4]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[temporal logic]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=469</guid>
		<description><![CDATA[My MFPS ’12 paper Towards a Common Categorical Semantics for Linear-Time Temporal Logic and Functional Reactive Programming has just been officially published by Elsevier. Here is my personal BibTeX entry for the paper: @article{jeltsch:entcs-286, author = {Jeltsch, Wolfgang}, title = {Towards a Common Categorical Semantics for Linear-Time Temporal Logic and Functional Reactive Programming}, journal = [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=469&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>My MFPS ’12 paper <em>Towards a Common Categorical Semantics for Linear-Time Temporal Logic and Functional Reactive Programming</em> has just been <a href="http://dx.doi.org/10.1016/j.entcs.2012.08.015" title="Towards a Common Categorical Semantics for Linear-Time Temporal Logic and Functional Reactive Programming">officially published by Elsevier</a>.<span id="more-469"></span></p>
<p>Here is my personal BibTeX entry for the paper:
<pre>@article{jeltsch:entcs-286,
    author       = {Jeltsch, Wolfgang},
    title        = {Towards a Common Categorical Semantics for
                    Linear-Time Temporal Logic and Functional
                    Reactive Programming},
    journal      = {Electronic Notes in Theoretical Computer
                    Science},
    volume       = 286,
    pages        = {229--242},
    numpages     = 14,
    publisher    = {Elsevier},
    address      = {Amsterdam, The Netherlands},
    month        = sep,
    year         = 2012,
    issn         = {1571-0661},
    doi          = {10.1016/j.entcs.2012.08.015}
}</pre>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/categorical-logic/'>categorical logic</a>, <a href='http://jeltsch.wordpress.com/tag/category-theory/'>category theory</a>, <a href='http://jeltsch.wordpress.com/tag/curry-howard-correspondence/'>Curry–Howard correspondence</a>, <a href='http://jeltsch.wordpress.com/tag/frp/'>FRP</a>, <a href='http://jeltsch.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://jeltsch.wordpress.com/tag/intuitionistic-logic/'>intuitionistic logic</a>, <a href='http://jeltsch.wordpress.com/tag/logic/'>logic</a>, <a href='http://jeltsch.wordpress.com/tag/ltl/'>LTL</a>, <a href='http://jeltsch.wordpress.com/tag/mfps/'>MFPS</a>, <a href='http://jeltsch.wordpress.com/tag/modal-logic/'>modal logic</a>, <a href='http://jeltsch.wordpress.com/tag/publication/'>publication</a>, <a href='http://jeltsch.wordpress.com/tag/s4/'>S4</a>, <a href='http://jeltsch.wordpress.com/tag/semantics/'>semantics</a>, <a href='http://jeltsch.wordpress.com/tag/temporal-logic/'>temporal logic</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/469/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/469/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=469&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2012/10/01/paper-on-categorical-models-of-temporal-logic-and-frp-published/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
		<item>
		<title>ucs 2.1 soon to appear on CTAN</title>
		<link>http://jeltsch.wordpress.com/2012/08/28/ucs-2-1-soon-to-appear-on-ctan/</link>
		<comments>http://jeltsch.wordpress.com/2012/08/28/ucs-2-1-soon-to-appear-on-ctan/#comments</comments>
		<pubDate>Tue, 28 Aug 2012 15:17:20 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CTAN]]></category>
		<category><![CDATA[LaTeX]]></category>
		<category><![CDATA[Ralf Meyer]]></category>
		<category><![CDATA[software release]]></category>
		<category><![CDATA[TeX]]></category>
		<category><![CDATA[ucs (LaTeX package)]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=463</guid>
		<description><![CDATA[I have just uploaded version&#160;2.1 of the LaTeX ucs package to CTAN, so it should appear there within the next few days. Some small bugs have been fixed, and mappings for several characters, mostly musical notes and special arrows, have been added. A big thank you goes to Ralf Meyer, who has contributed considerably to [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=463&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I have just uploaded version&nbsp;2.1 of <a href="https://wolfgang.jeltsch.info/software/tex/ucs" title="ucs">the LaTeX ucs package</a> to CTAN, so it should appear there within the next few days. Some small bugs have been fixed, and mappings for several characters, mostly musical notes and special arrows, have been added. A big thank you goes to <a href="http://xwww.uni-math.gwdg.de/template/?userid=3864&amp;username=rameyer" title="Ralf Meyer">Ralf Meyer</a>, who has contributed considerably to this release.<span id="more-463"></span></p>
<p>I am always happy to receive bug reports, wishlists, and contributions. Just <a href="http://cs.ioc.ee/dept/staff/wolfgang.html" title="Wolfgang Jeltsch">get in touch with me</a>.</p>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/ctan/'>CTAN</a>, <a href='http://jeltsch.wordpress.com/tag/latex/'>LaTeX</a>, <a href='http://jeltsch.wordpress.com/tag/ralf-meyer/'>Ralf Meyer</a>, <a href='http://jeltsch.wordpress.com/tag/software-release/'>software release</a>, <a href='http://jeltsch.wordpress.com/tag/tex/'>TeX</a>, <a href='http://jeltsch.wordpress.com/tag/ucs-latex-package/'>ucs (LaTeX package)</a>, <a href='http://jeltsch.wordpress.com/tag/unicode/'>Unicode</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/463/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/463/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=463&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2012/08/28/ucs-2-1-soon-to-appear-on-ctan/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
		<item>
		<title>Slides of my MFPS talk now online</title>
		<link>http://jeltsch.wordpress.com/2012/07/10/slides-of-my-mfps-talk-now-online/</link>
		<comments>http://jeltsch.wordpress.com/2012/07/10/slides-of-my-mfps-talk-now-online/#comments</comments>
		<pubDate>Tue, 10 Jul 2012 17:34:58 +0000</pubDate>
		<dc:creator>Wolfgang Jeltsch</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[categorical logic]]></category>
		<category><![CDATA[category theory]]></category>
		<category><![CDATA[Curry–Howard correspondence]]></category>
		<category><![CDATA[FRP]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[intuitionistic logic]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[LTL]]></category>
		<category><![CDATA[MFPS]]></category>
		<category><![CDATA[modal logic]]></category>
		<category><![CDATA[publication]]></category>
		<category><![CDATA[S4]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[talk]]></category>
		<category><![CDATA[temporal logic]]></category>

		<guid isPermaLink="false">http://jeltsch.wordpress.com/?p=450</guid>
		<description><![CDATA[MFPS took place a month ago, and today I finally managed to publish the slides of my talk . The topic of these slides is similar to the topic of the seminar talk I gave at 10&#160;May, but the overlap is not too large. So you might be interested in having a look. Tagged: categorical [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=450&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>MFPS took place a month ago, and today I finally managed to publish <a href="http://www.ioc.ee/~wolfgang/research/mfps-2012-slides.pdf" title="Towards a Common Categorical Semantics for Linear-Time Temporal Logic and Functional Reactive Programming">the slides of my talk</a> <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . The topic of these slides is similar to the topic of <a href="http://jeltsch.wordpress.com/2012/05/18/talk-about-categorical-models-of-temporal-logic-and-frp/" title="Talk about categorical models of temporal logic and FRP">the seminar talk I gave at 10&nbsp;May</a>, but the overlap is not too large. So you might be interested in having a look.</p>
<br /> Tagged: <a href='http://jeltsch.wordpress.com/tag/categorical-logic/'>categorical logic</a>, <a href='http://jeltsch.wordpress.com/tag/category-theory/'>category theory</a>, <a href='http://jeltsch.wordpress.com/tag/curry-howard-correspondence/'>Curry–Howard correspondence</a>, <a href='http://jeltsch.wordpress.com/tag/frp/'>FRP</a>, <a href='http://jeltsch.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://jeltsch.wordpress.com/tag/intuitionistic-logic/'>intuitionistic logic</a>, <a href='http://jeltsch.wordpress.com/tag/logic/'>logic</a>, <a href='http://jeltsch.wordpress.com/tag/ltl/'>LTL</a>, <a href='http://jeltsch.wordpress.com/tag/mfps/'>MFPS</a>, <a href='http://jeltsch.wordpress.com/tag/modal-logic/'>modal logic</a>, <a href='http://jeltsch.wordpress.com/tag/publication/'>publication</a>, <a href='http://jeltsch.wordpress.com/tag/s4/'>S4</a>, <a href='http://jeltsch.wordpress.com/tag/semantics/'>semantics</a>, <a href='http://jeltsch.wordpress.com/tag/talk/'>talk</a>, <a href='http://jeltsch.wordpress.com/tag/temporal-logic/'>temporal logic</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jeltsch.wordpress.com/450/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jeltsch.wordpress.com/450/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jeltsch.wordpress.com&#038;blog=33918393&#038;post=450&#038;subd=jeltsch&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jeltsch.wordpress.com/2012/07/10/slides-of-my-mfps-talk-now-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/bf139729e2f2ed2494653dda9da99a38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jeltsch</media:title>
		</media:content>
	</item>
	</channel>
</rss>
