<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sadek Drobi's Blog &#187; Haskell</title>
	<atom:link href="http://sadekdrobi.com/category/haskell/feed/" rel="self" type="application/rss+xml" />
	<link>http://sadekdrobi.com</link>
	<description>Sadek Drobi</description>
	<lastBuildDate>Tue, 08 Mar 2011 22:56:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Functional Web: Functional Programing for Web Integration and Mashups</title>
		<link>http://sadekdrobi.com/2010/11/16/functional-web-functional-programing-for-web-integration-and-mashups/</link>
		<comments>http://sadekdrobi.com/2010/11/16/functional-web-functional-programing-for-web-integration-and-mashups/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 22:17:18 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[fsharp]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[mashups]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[woa]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/?p=705</guid>
		<description><![CDATA[Functional programming is often perceived as being good for either mathematics or multi-core programming. As for its huge benefits for modern web architecture and development, they are not really known. This video gives a few arguments about why functional programming matters for today’s and tomorrow’s web.
http://www.zengularity.com/item/1519646134/functional-web-functional-programing-for-web
]]></description>
			<content:encoded><![CDATA[<p>Functional programming is often perceived as being good for either mathematics or multi-core programming. As for its huge benefits for modern web architecture and development, they are not really known. This video gives a few arguments about why functional programming matters for today’s and tomorrow’s web.</p>
<p><a href="http://www.zengularity.com/item/1519646134/functional-web-functional-programing-for-web">http://www.zengularity.com/item/1519646134/functional-web-functional-programing-for-web</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2010/11/16/functional-web-functional-programing-for-web-integration-and-mashups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Computation Abstraction Talk Slides for Functional Exchange</title>
		<link>http://sadekdrobi.com/2009/12/07/my-computation-abstraction-slides-for-functional-exchange/</link>
		<comments>http://sadekdrobi.com/2009/12/07/my-computation-abstraction-slides-for-functional-exchange/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 17:46:25 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[LinQ]]></category>
		<category><![CDATA[Scala Haskell fsharp fp monads csharp]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/12/07/my-computation-abstraction-slides-for-functional-exchange/</guid>
		<description><![CDATA[Computation Abstraction: Going beyond programming language control syntax, or what we&#8217;ve missed from FP for so long in mainstream
For a long time, and due to the lack of main FP concepts in most mainstream languages, we missed opportunities to abstraction and code expressiveness and conciseness. With today&#8217;s democratization of FP, Computational Abstraction is what will [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Computation Abstraction: Going beyond programming language control syntax, or what we&#8217;ve missed from FP for so long in mainstream</strong></p>
<p>For a long time, and due to the lack of main FP concepts in most mainstream languages, we missed opportunities to abstraction and code expressiveness and conciseness. With today&#8217;s democratization of FP, Computational Abstraction is what will enable us to be less dependent on specific programming language syntax offering; creating libraries of control structures and composition forms that help find concise and expresive solutions to enterprise programming challenges (null, lists treatment, error handling), capturing elegantly important business concepts in code, and programming at the right level of abstraction.For a long time, and due to the lack of main FP concepts in most mainstream languages, we missed opportunities to abstraction and code expressiveness and conciseness. With today&#8217;s democratization of FP, Computational Abstraction is what will enable us to be less dependent on specific programming language syntax offering; creating libraries of control structures and composition forms that help find concise and expresive solutions to enterprise programming challenges (null, lists treatment, error handling), capturing elegantly important business concepts in code, and programming at the right level of abstraction. </p>
<p>Slides:&#160; <a href="http://sadekdrobi.com/wp-content/uploads/2009/12/Computation-Abstraction666iiioii6jjjjjjhjj-5.pdf">http://sadekdrobi.com/wp-content/uploads/2009/12/Computation-Abstraction666iiioii6jjjjjjhjj-5.pdf</a></p>
<p>Google wave:&#160; <a href="https://wave.google.com/wave/#restored:wave:googlewave.com!w%252BPgcakhgiA">https://wave.google.com/wave/#restored:wave:googlewave.com!w%252BPgcakhgiA</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/12/07/my-computation-abstraction-slides-for-functional-exchange/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Side Effects</title>
		<link>http://sadekdrobi.com/2009/11/06/683/</link>
		<comments>http://sadekdrobi.com/2009/11/06/683/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 16:11:41 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Erlang]]></category>
		<category><![CDATA[fp]]></category>
		<category><![CDATA[side effect free]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/?p=683</guid>
		<description><![CDATA[Most of my Erlang programming is side effect free. I think I probably write very unusual Erlang programs that look a lot like Haskell ones. Now and then, I do write side effecting code. For example, when I use the random number generation libraries that comes with Erlang, it has a side effecting interface. It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Most of my Erlang programming is side effect free. I think I probably write very unusual Erlang programs that look a lot like Haskell ones. Now and then, I do write side effecting code. For example, when I use the random number generation libraries that comes with Erlang, it has a side effecting interface. It&#8217;s very tempting when you are building something on top of the library with a stateful interface to build code on top of that that also has a stateful interface. </p>
<p>That&#8217;s what I did the first time I tried to use it. That has caused me so much trouble. I think every single bug that I spent hours trying to track down has been caused by a side effect. In a way, I&#8217;ve been programming Haskell for so many years, that I&#8217;d forgotten just how devastating side effects are and just how difficult they make debugging. I&#8217;ve learnt that lesson again and nowadays, if I want to use a stateful library, I usually build a side effect free interface on top of it, so that I can then use it safely in the rest of my code.</p></blockquote>
<p>from my <a href="http://www.infoq.com/interviews/Erlang-Haskell-John-Hughes">interview with John Hughes</a> at <a href="http://www.erlang-factory.com/">Erlang Factory</a> </p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/11/06/683/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A monad in C# for simplifying WPF multi-threading for a more responsive GUI</title>
		<link>http://sadekdrobi.com/2009/06/26/a-monad-in-c-for-simplifying-wpf-multi-threading-for-a-more-responsive-gui/</link>
		<comments>http://sadekdrobi.com/2009/06/26/a-monad-in-c-for-simplifying-wpf-multi-threading-for-a-more-responsive-gui/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 19:13:40 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[DOTNET]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[LinQ]]></category>
		<category><![CDATA[MVP]]></category>
		<category><![CDATA[Multi-Paradigm Design]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Monads]]></category>
		<category><![CDATA[Thread]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/?p=563</guid>
		<description><![CDATA[
Code included here is over simplified for clarity, I hosted a better implementation code on CodePlex. These  modifications change strictly nothing for the client code and are only an implementation detail. I use a continuation rather than a delay, and I chose to design a custom continuation class rather than using a delegate because [...]]]></description>
			<content:encoded><![CDATA[<div style="font-family: courier new; background: white; color: gray; font-size: 10pt">
<p>Code included here is over simplified for clarity, I hosted a better implementation code on <a href="http://viewmonad.codeplex.com/sourcecontrol/changeset/view/22890?projectName=viewmonad#447750">CodePlex</a>. These  modifications change strictly nothing for the client code and are only an implementation detail. I use a continuation rather than a delay, and I chose to design a custom continuation class rather than using a delegate because of a type system limitations.</p>
</div>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2008/12/dsc-2468.jpg"><img style="border-right-width: 0px; margin: 0px 15px 0px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="DSC_2468" align="left" src="http://sadekdrobi.com/wp-content/uploads/2008/12/dsc-2468-thumb-196x300.jpg" width="279" height="426"></a>Most GUI frameworks, including Silverlight and WPF, are shipped with a fundamental problem: long use of the main thread causes the Window to blackout, and using different threads requires you to get your hands dirty with the Dispatcher stuff and freezable objects. Worse, you wont learn the necessity to do so until you get a surprise of &#8220;The calling thread cannot access this object because a different thread owns it.&#8221; exception when all what you were doing is to use available methods on an object that seemed you have access to, at lease it seemed until runtime! This post illustrates a solution based on Monads abstraction and LinQ syntax.<br />
<span id="more-563"></span></p>
<p>This is a problem you get often when applying Model View Presenter pattern [MVP]. There, your view (which is a WPF control) implements a contract IView that the presenter in its turn will use to extract values and then make operations on the view.</p>
<p>&nbsp;</p>
<p><em>interface ISayHello { string GetName(); Unit SayHello(string name); } </em></p>
<p><em>class MyLoginControl:Control,<strong>ISayHello </strong>{</em></p>
<p><em>//this interface gets implemented by the corresponding control as texboxes and a text area&#8230;</em></p>
<p><em>}</em></p>
<p>The problem appears when for doing any realistic responsive application, the presenter (representing business operations if you&#8217;d like) will have to run on a background thread to leave the main thread free for graphics rendering.</p>
<p>While working on a background thread, the presenter needs to access the view (having a reference to it through a contract) and there something wrong happen <strong>&#8220;The calling thread cannot access this object because a different thread owns it.&#8221;</strong> .&nbsp; </p>
<p>The problem here is simply that the view is giving quite a promise that it simply can not satisfy which is implementing the IView contract.</p>
<p>The view cannot satisfy the <em><strong>ISayHello </strong></em>contract under all circumstances, and not even under a commonly desirable condition (the presenter or business code running on another thread). This fact is simply not communicated through the type.</p>
<p>The solution I suggest to this problem that I implemented and employed in a production real world project is based on the LinQ syntax added to C# last year. In the solution I use two things: an extension method and a special type.</p>
<p>The type that I use is the monadic type (thanks to Wesdyer for his enlightening posts): <em><strong>View&lt;T&gt;</strong></em></p>
<p>So in my case my type will be View&lt;IView&gt; which means that what I am offering here is a a type that acts under some special circumstances as the Contract <em><strong>ISayHello</strong></em> . If I want for example to extract the name from the WPF control, I need to do something with the <strong><em><em><strong>View&lt;ISayHello&gt;</strong></em>.</em></strong>&nbsp;</p>
<h2>Using the View&lt;T&gt; Monad:</h2>
<p>And here comes the LinQ syntax for help. Having a reference to <em><strong>View&lt;ISayHello&gt;</strong></em>, the only way with which I can access the desired value or methods is using <strong>Linq</strong>:</p>
<p>Having the view contract: </p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs20 \cf1 public\cf0  \cf1 interface\cf0  \cf4 ISayHello\par ??\cf0     \{\par ??        \cf4 Unit\cf0  SayHello(\cf1 string\cf0  Name);\par ??        \cf1 string\cf0  GetName();\par ??    \}\par ??    }<br />
--></p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">interface</span> <span style="color: #2b91af">ISayHello</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">Unit</span> SayHello(<span style="color: blue">string</span> Name);</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">string</span> GetName();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp; } <a href="$image[43].png"></a>&nbsp;<a href="$image[22].png"></a> </p>
</div>
<p>I can extract a view monad that I can pass to the presenter as <em><strong>View&lt;ISayHello&gt;</strong></em>&nbsp;</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red43\green145\blue175;\red255\green255\blue255;\red0\green0\blue0;\red0\green0\blue255;}??\fs20 \cf1 View\cf0 &lt;\cf1 ISayHello\cf0 &gt; view = \cf4 this\cf0 .AsView&lt;\cf1 Window1\cf0 , \cf1 ISayHello\cf0 &gt;();}<br />
--></p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span><span style="color: #2b91af">View</span>&lt;<span style="color: #2b91af">ISayHello</span>&gt; view = <span style="color: blue">this</span>.AsView&lt;<span style="color: #2b91af">Window1</span>, <span style="color: #2b91af">ISayHello</span>&gt;(); </p>
</div>
<p>note the type <em><strong>View&lt;ISayHello&gt;</strong></em> which is somehow useless without the LinQ syntax:</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;}??\fs20 (\cf3 from\cf0  v \cf3 in\cf0  view\par ??                \cf3 let\cf0  name = v.GetName()\par ??                \cf3 select\cf0  v.SayHello(name)).Do();}<br />
--></p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>(<span style="color: blue">from</span> v <span style="color: blue">in</span> view</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;<span style="color: blue">let</span> name = v.GetName()</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;<span style="color: blue">select</span> v.SayHello(name)).Do();</p>
</div>
<p>and you can also use several contracts in the same expression:</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;}??\fs20 \cf1 from\cf0  v \cf1 in\cf0  view1\par ??                \cf1 from\cf0  v2 \cf1 in\cf0  view2}<br />
--></p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span><span style="color: blue">from</span> v <span style="color: blue">in</span> view1</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span><span style="color: blue">from</span> v2 <span style="color: blue">in</span> view2</p>
<p style="margin: 0px">&nbsp;</p>
<p style="margin: 0px">&nbsp;</p>
</div>
<h2>Implementation of the View&lt;T&gt; Monad:</h2>
<p>&nbsp;</p>
<p>View&lt;T&gt; is not really special. It is just a Delay&lt;T&gt; which is a Func&lt;T&gt;. And the Select implementation is the same one for functions and is not special at all: </p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs20 \cf1 public\cf0  \cf1 delegate\cf0  R \cf4 View\cf0 &lt;R&gt;();}<br />
--></p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">delegate</span> R <span style="color: #2b91af">View</span>&lt;R&gt;();</p>
</div>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs20 \cf1 public\cf0  \cf1 enum\cf0  \cf4 Unit\par ??\cf0     \{\par ??        Unit\par ??    \}\par ??    \cf1 public\cf0  \cf1 static\cf0  \cf1 class\cf0  \cf4 WPFMonadExtensions\par ??\cf0     \{\par ??        \cf1 public\cf0  \cf1 static\cf0  \cf4 View\cf0 &lt;U&gt; SelectMany&lt;T, U&gt;(\cf1 this\cf0  \cf4 View\cf0 &lt;T&gt; m, \cf4 Func\cf0 &lt;T, \cf4 View\cf0 &lt;U&gt;&gt; k)\par ??        \{\par ??            \cf1 return\cf0  () =&gt; k(m())();\par ??        \}\par ??        \cf1 public\cf0  \cf1 static\cf0  \cf4 View\cf0 &lt;U&gt; Select&lt;T, U&gt;(\cf1 this\cf0  \cf4 View\cf0 &lt;T&gt; m, \cf4 Func\cf0 &lt;T, U&gt; selector)\par ??        \{\par ??            \cf1 return\cf0  () =&gt; selector(m());\par ??        \}\par ??        \cf1 public\cf0  \cf1 static\cf0  \cf4 View\cf0 &lt;V&gt; SelectMany&lt;T, U, V&gt;(\cf1 this\cf0  \cf4 View\cf0 &lt;T&gt; source, \cf4 Func\cf0 &lt;T, \cf4 View\cf0 &lt;U&gt;&gt; kSelector, \cf4 Func\cf0 &lt;T, U, V&gt; resultSelector)\par ??        \{\par ??            \cf1 return\cf0  () =&gt;\par ??                       \{\par ??                           \cf1 var\cf0  t = source();\par ??                           \cf1 var\cf0  u = kSelector(t)();\par ??                           \cf1 return\cf0  resultSelector(t, u);\par ??                       \};\par ??        \}\par ??        \cf1 public\cf0  \cf1 static\cf0  \cf4 Unit\cf0  Do(\cf1 this\cf0  \cf4 View\cf0 &lt;\cf4 Unit\cf0 &gt; k)\par ??        \{\par ??            \cf1 return\cf0  k();\par ??        \}}<br />
--></p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">enum</span> <span style="color: #2b91af">Unit</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Unit</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: blue">class</span> <span style="color: #2b91af">WPFMonadExtensions</span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: #2b91af">View</span>&lt;U&gt; SelectMany&lt;T, U&gt;(<span style="color: blue">this</span> <span style="color: #2b91af">View</span>&lt;T&gt; m, <span style="color: #2b91af">Func</span>&lt;T, <span style="color: #2b91af">View</span>&lt;U&gt;&gt; k)</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> () =&gt; k(m())();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: #2b91af">View</span>&lt;U&gt; Select&lt;T, U&gt;(<span style="color: blue">this</span> <span style="color: #2b91af">View</span>&lt;T&gt; m, <span style="color: #2b91af">Func</span>&lt;T, U&gt; selector)</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> () =&gt; selector(m());</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: #2b91af">View</span>&lt;V&gt; SelectMany&lt;T, U, V&gt;(<span style="color: blue">this</span> <span style="color: #2b91af">View</span>&lt;T&gt; source, <span style="color: #2b91af">Func</span>&lt;T, <span style="color: #2b91af">View</span>&lt;U&gt;&gt; kSelector, <span style="color: #2b91af">Func</span>&lt;T, U, V&gt; resultSelector)</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> () =&gt;</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> t = source();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> u = kSelector(t)();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> resultSelector(t, u);</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: #2b91af">Unit</span> Do(<span style="color: blue">this</span> <span style="color: #2b91af">View</span>&lt;<span style="color: #2b91af">Unit</span>&gt; k)</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> k();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
<p>The fact that I am defining a new delegate type here (View&lt;T&gt;) is because we don&#8217;t have type synonyms is C#. And because of this I had to reimplement all the Select methods for this type. Of course all of that Monad plumping code is invisible and all the user needs to do is use the LinQ syntax.</p>
<p>The only specific part about the View monad, is the way you extract it. For Wpf for example the .AsView implementation looks like: </p>
<p>&nbsp;</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;}??\fs20 \cf1 public\cf0  \cf1 static\cf0  \cf4 View\cf0 &lt;TView&gt; AsView&lt;TWPF, TView&gt;(\cf1 this\cf0  TWPF value) \cf1 where\cf0  TWPF : \cf4 UIElement\cf0 , TView\par ??        \{\par ??            \cf1 return\cf0  value.ToWpfMonad&lt;TWPF, TView&gt;();\par ??        \}\par ??\par ??        \cf1 public\cf0  \cf1 static\cf0  \cf4 View\cf0 &lt;Answer&gt; ToWpfMonad&lt;T, Answer&gt;(\cf1 this\cf0  T value)\par ??           \cf1 where\cf0  T : \cf4 UIElement\cf0 , Answer\par ??        \{\par ??            \cf1 return\cf0  () =&gt;\par ??            \{\par ??                Answer a = \cf1 default\cf0 (Answer);\par ??                value.Dispatcher.Invoke(\cf4 DispatcherPriority\cf0 .Normal, (\cf4 EventHandler\cf0 )((sender, e) =&gt;\par ??                \{\par ??                    a = value;\par ??                    \cf1 if\cf0  (a \cf1 is\cf0  \cf4 Freezable\cf0 )\par ??                    \{\par ??                        \cf1 var\cf0  result = ((\cf4 Freezable\cf0 )(\cf1 object\cf0 )a).Clone();\par ??                        a = (Answer)(\cf1 object\cf0 )result;\par ??                        result.Freeze();\par ??                    \}\par ??                \}), \cf1 null\cf0 , \cf1 null\cf0 );\par ??\par ??                \cf1 return\cf0  a;\par ??            \};\par ??        \}}<br />
--></p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span><span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: #2b91af">View</span>&lt;TView&gt; AsView&lt;TWPF, TView&gt;(<span style="color: blue">this</span> TWPF value) <span style="color: blue">where</span> TWPF : <span style="color: #2b91af">UIElement</span>, TView</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> value.ToWpfMonad&lt;TWPF, TView&gt;();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: #2b91af">View</span>&lt;Answer&gt; ToWpfMonad&lt;T, Answer&gt;(<span style="color: blue">this</span> T value)</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">where</span> T : <span style="color: #2b91af">UIElement</span>, Answer</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> () =&gt;</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Answer a = <span style="color: blue">default</span>(Answer);</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value.Dispatcher.Invoke(<span style="color: #2b91af">DispatcherPriority</span>.Normal, (<span style="color: #2b91af">EventHandler</span>)((sender, e) =&gt;</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = value;</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (a <span style="color: blue">is</span> <span style="color: #2b91af">Freezable</span>)</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> result = ((<span style="color: #2b91af">Freezable</span>)(<span style="color: blue">object</span>)a).Clone();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a = (Answer)(<span style="color: blue">object</span>)result;</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result.Freeze();</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }), <span style="color: blue">null</span>, <span style="color: blue">null</span>);</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span></p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> a;</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</p>
<p style="margin: 0px"><span style="color: #2b91af">&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
<p>Which merely tells about how to execute the delay when applied.</p>
<p>This is the code responsible for calling on WPF windows using dispatcher and other plumping details. Again code here is simplified for clarity. In the same way one can implement an AsView extension method for Silverlight with no need to change the Select implementation. View&lt;T&gt; is a generic monad and contain nothing specific to GUI technology.</p>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>The Monad generalization provides a good solution for WPF/Silverlight thread problem. The solution is barely about communicating through the type system the fact that WPF/Silverlight <em>controls</em> are special, and using LinQ expression to operate on them leaving the plumping (Dispatcher.Invoke, Freezable) to the monad library implementers. Also this frees the caller from thread logic that is specific to the implementation technology. </p>
<p>In my project I didn&#8217;t work much on the freezing/unfreezing of Wpf controls (copy them and extract them to other threads) as it actually wasn&#8217;t necessary for my project. However, I think that a proper implementation of .AsView for WPF/Silverlight that manages Freezable and nested Freezable objects copying would be very interesting and would complete the API.</p>
<p>PS: I decided to finish this draft quickly as I am not having enough time to finish properly. Please tolerate typos and don&#8217;t hesitate to ask questions.</p>
<p/>
<div style="font-family: courier new; background: white; color: red; font-size: 10pt">The running example with a better implementation that is rather based on continuations is hosted on <a href="http://viewmonad.codeplex.com/sourcecontrol/changeset/view/22890?projectName=viewmonad#447750">CodePlex</a></div>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/06/26/a-monad-in-c-for-simplifying-wpf-multi-threading-for-a-more-responsive-gui/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Paul Hudak on Haskell</title>
		<link>http://sadekdrobi.com/2009/05/08/paul-hudak-on-haskell/</link>
		<comments>http://sadekdrobi.com/2009/05/08/paul-hudak-on-haskell/#comments</comments>
		<pubDate>Fri, 08 May 2009 14:52:31 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[InfoQ]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/05/08/paul-hudak-on-haskell/</guid>
		<description><![CDATA[An interview I did with Paul Hudak that begins with a discussion of when to introduce difficult Haskell concepts like monads, moves to a discussion of the philosophy of higher order programming, the success and influence of Haskell, its use in the mainstream, and concludes with the idea of teaching computer music and Haskell simultaneously.
&#160;
http://www.infoq.com/interviews/paul-hudak-haskell-Qcon-SF-08&#38;language=en
]]></description>
			<content:encoded><![CDATA[<p>An interview I did with Paul Hudak that begins with a discussion of when to introduce difficult Haskell concepts like monads, moves to a discussion of the philosophy of higher order programming, the success and influence of Haskell, its use in the mainstream, and concludes with the idea of teaching computer music and Haskell simultaneously.</p>
<p>&nbsp;</p>
<p><a href="http://www.infoq.com/interviews/paul-hudak-haskell-Qcon-SF-08&amp;language=en">http://www.infoq.com/interviews/paul-hudak-haskell-Qcon-SF-08&amp;language=en</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/05/08/paul-hudak-on-haskell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Abstraction for People: Configurations, Patterns, DSLs and Monads</title>
		<link>http://sadekdrobi.com/2009/03/29/abstraction-for-people-configurations-patterns-dsls-and-monads/</link>
		<comments>http://sadekdrobi.com/2009/03/29/abstraction-for-people-configurations-patterns-dsls-and-monads/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 23:10:53 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[DOTNET]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[LinQ]]></category>
		<category><![CDATA[Model Mismatch]]></category>
		<category><![CDATA[Paradigm Oriented Programming Language]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Useability]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/03/29/abstraction-for-people-configurations-patterns-dsls-and-monads/</guid>
		<description><![CDATA[

LinQ is often understood in terms of introducing a Domain Specific Language to work with data to C# and .Net in general. The fact is:it is not, and there is a considerable difference between LinQ syntax nature and a DSL. The problem is that DSL definition is blur enough to take anything interesting or cool [...]]]></description>
			<content:encoded><![CDATA[</p>
<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/03/dsc-2692a3.jpg"><img style="border-right-width: 0px; margin: 0px 20px 0px 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="DSC_2692a3" align="left" src="http://sadekdrobi.com/wp-content/uploads/2009/03/dsc-2692a3-thumb.jpg" width="222" height="327"></a></p>
<p>LinQ is often understood in terms of introducing a Domain Specific Language to work with data to C# and .Net in general. The fact is:it is not, and there is a considerable difference between LinQ syntax nature and a DSL. The problem is that DSL definition is blur enough to take anything interesting or cool under it!</p>
<p><span id="more-596"></span>
<p>Back to the beginning. When faced to doing software for a business that has some moving parts, a good practice is to make a generalization or an abstraction of the fixed part and express what is moving through some sort of configurations. That is in some respect what most of enterprise frameworks do when implementing the fixed part and letting you nicely only express what varies for your context. This way you are almost only concerned about your part since the framework itself is supposed to be steady and well abstracted and as a result implicit in your context. This experience hasn&#8217;t been nice enough when XML used to be involved. As someone that defends multi-paradigm design I could argue that XML can play a best fit in some contexts but this is out of the scope of this post. XML charset is not optimal for a lot of cases, so why not creating our own charset, and here comes DSLs.</p>
<p>Of course here I am only talking about the rise of DSLs in the enterprise and not the DSLs that FP been doing for ages, and I&#8217;ll get back to this one later.</p>
<p>Now using my favorite meta magical super dynamic language, I&#8217;d like to construct my customized embedded(or internal) domain specific language, and I&#8217;ll make my best to be English like/business like/ host language unlike to be really specific. And that is where my brains blocks! How can I get grasp of that thing, that &#8216;lil&#8217; language? It might be a personal problem I have because of the nature of my profession as a consultant: I switch contexts often, and&#8230; well I can only hope that it is 1:designed, 2: designed considering practices, rules and well established&#8230; did I say patterns?</p>
<p>&nbsp;</p>
<h3>P for Patterns :</h3>
<p>Another way of providing a solution to the problem of generality/variability is use a catalogue of non-formal generalization of recurring solutions to recurrent problems that provide a rich knowledge base of experience about tackling the kind of problem. Being of non-formal nature means that patterns aren&#8217;t provided as a framework but rather as a set of vocabulary and description that has its power in being adaptive&nbsp; and flexible. In my own experience, what I found particularly interesting when working with code that uses patterns is the way they communicate intent. If I find &#8220;Strategy&#8221; postfix I start searching for the other parts of the patterns and then start building on that. Providing this shared vocabulary helps me getting operational quite fast and help me scan code faster in a more &#8220;visual&#8221; way.</p>
<p>The good thing also about patterns is that I am still playing under the rules of my preferred hosting language. I know very well doing two very important things with it: combining and abstraction. A programming language is a set primitives together with a way to combine them and a mechanism for abstraction. What about my lil DSL? well it depends&#8230; Did I make sure to break any host language logic in there? Did I fight the intuitive nice &#8220;.&#8221;? Or did I decide that to implement my DSL for scratch? A programming language without means of abstraction results inevitably in long flat copy/paste configurations files and please don&#8217;t argue with me about their maintainability. What is the problem? The problem is that I am not a programming language designer, and to create a programming language no matter how simple and small it is, you need to have programming language design skills, so do you?</p>
<h3>Abstraction and Communication for People:</h3>
<p>Something that really drew my attention in functional programming languages like Haskell is their solid formal abstractions used for expressing computational patterns. These abstractions are packaged into a framework, and have a clear identity defined by a set of rules and are useable whenever semantics match. Take monads for example. It doesn&#8217;t matter if you are working with state, a database, the web, the screen or a robitic arm: you just use the do notation. The do notation in Haskell is a convenient way of working with a sound abstraction that is <a href="http://en.wikipedia.org/wiki/Monads_in_functional_programming">THE MONAD</a>. And all what you need to do for your framework is to verify that you satisfy the Monad laws and then you can safely use that syntax for it. This sharing of well identified semantics of the abstraction help developers reuse a well established mental model. LinQ syntax is the same, the dot &#8220;.&#8221; operator is the same, F#&#8217;s&nbsp; &#8220;|&gt;&#8221; operator is the same and examples are a lot. And I tend to prefer these kind of abstractions as they don&#8217;t sacrifice readability for developers for &#8220;readability&#8221; for users. I guess they have both the communicative property of Design Patterns yet they are formal and are offered as a concrete framework. Then of course you can name them DSLs, if you insist :) .</p>
<p>Now, if you are from the functional programming camp, and you have been doing embedded domain specific language using Lisp or Haskell for long time, then I apologize for wasting your time. I know you guys know best about doing abstractions, and you have lessons to tell if we&#8217;d only listen. And for those interested in some examples in EDSLs from the functional world, <a href="http://www.amazon.com/Haskell-School-Expression-Functional-Programming/dp/0521644089/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1238371080&amp;sr=1-1">Paul Hudak goes through the design of a language for reactive animation in his book</a>, <a href="http://augustss.blogspot.com/">Lennart Augustsson</a> discussed EDSLs in Haskell on his blog.</p>
<h3>Conclusion</h3>
<p>Though an attractive option of abstraction, DSLs trade off readability for developers for &#8220;potential&#8221; readability of users. Haskell monads, F#&#8217;s &#8220;|&gt;&#8221; operator and LinQ are examples of sound formal abstraction that can be offered as frameworks (code). These abstractions can save developers time being in a form of a recurring pattern that can be used in different contexts that match semantically, thus reusing developers&#8217; understanding of the abstraction&#8217;s mental model. </p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/03/29/abstraction-for-people-configurations-patterns-dsls-and-monads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interview: Don Syme Answering Questions on F#, C#, Haskell and Scala</title>
		<link>http://sadekdrobi.com/2009/03/29/interview-don-syme-answering-questions-on-f-c-haskell-and-scala/</link>
		<comments>http://sadekdrobi.com/2009/03/29/interview-don-syme-answering-questions-on-f-c-haskell-and-scala/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 21:14:57 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[InfoQ]]></category>
		<category><![CDATA[LinQ]]></category>
		<category><![CDATA[Polyglot Programming]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/03/29/interview-don-syme-answering-questions-on-f-c-haskell-and-scala/</guid>
		<description><![CDATA[A great discussion I had with Don Syme at QCon SF. Don is one of the heroes to thank for .Net generics and he is a major contributor to F# design, Thanks Don!
http://www.infoq.com/interviews/F-Sharp-Don-Syme
]]></description>
			<content:encoded><![CDATA[<p>A great discussion I had with Don Syme at QCon SF. Don is one of the heroes to thank for .Net generics and he is a major contributor to F# design, Thanks Don!</p>
<p><a href="http://www.infoq.com/interviews/F-Sharp-Don-Syme">http://www.infoq.com/interviews/F-Sharp-Don-Syme</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/03/29/interview-don-syme-answering-questions-on-f-c-haskell-and-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Erik Mejier: LinQ, Beyond List Comprehensions in C# and .Net</title>
		<link>http://sadekdrobi.com/2009/03/05/erik-mejier-linq-beyond-list-comprehensions-in-c-and-net/</link>
		<comments>http://sadekdrobi.com/2009/03/05/erik-mejier-linq-beyond-list-comprehensions-in-c-and-net/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 21:55:53 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[DOTNET]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[InfoQ]]></category>
		<category><![CDATA[LinQ]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/03/05/erik-mejier-linq-beyond-list-comprehensions-in-c-and-net/</guid>
		<description><![CDATA[Erik Meijer talks about less known LINQ features, like meta programming, about the differences between functional languages and OO ones, asynchronous computation, and others.

http://www.infoq.com/interviews/LINQ-Erik-Meijer
]]></description>
			<content:encoded><![CDATA[<p>Erik Meijer talks about less known LINQ features, like meta programming, about the differences between functional languages and OO ones, asynchronous computation, and others.</p>
<p><span id="more-591"></span></p>
<p><a href="http://www.infoq.com/interviews/LINQ-Erik-Meijer">http://www.infoq.com/interviews/LINQ-Erik-Meijer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/03/05/erik-mejier-linq-beyond-list-comprehensions-in-c-and-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I am speaking at QCon</title>
		<link>http://sadekdrobi.com/2009/02/18/i-am-speaking-at-qcon/</link>
		<comments>http://sadekdrobi.com/2009/02/18/i-am-speaking-at-qcon/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 18:00:06 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[InfoQ]]></category>
		<category><![CDATA[LinQ]]></category>
		<category><![CDATA[Multi-Paradigm Design]]></category>
		<category><![CDATA[QCon]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/02/18/i-am-speaking-at-qcon/</guid>
		<description><![CDATA[
 
&#160;

Programming with a Mainstream Language
Track: Functional and Concurrent Programming Languages Applied
Time: Thursday 17:15 &#8211; 18:15
Location: Abbey Room
Abstract:
Using functional programming (FP) in enterprise software development is often quite a challenge. In this presentation, Sadek Drobi will talk about his experience of applying functional programming principles on a real-world project in relation with existing non-functional frameworks.
In [...]]]></description>
			<content:encoded><![CDATA[</p>
<p><a href="http://qconlondon.com/london-2009/presentation/Functional+Programming+with+a+Mainstream+Language"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="download (1)" src="http://sadekdrobi.com/wp-content/uploads/2009/02/download-1.jpg" width="547" height="196"></a> </p>
<p>&nbsp;</p>
<p><span id="more-590"></span></p>
<p><strong><a href="http://qconlondon.com/london-2009/presentation/Functional+Programming+with+a+Mainstream+Language">Programming with a Mainstream Language</a></strong></p>
<p><strong>Track</strong>: <a href="http://qconlondon.com/london-2009/tracks/show_track.jsp?trackOID=225">Functional and Concurrent Programming Languages Applied</a>
<p><strong>Time</strong>: Thursday 17:15 &#8211; 18:15
<p><strong>Location</strong>: Abbey Room
<p><strong>Abstract</strong>:
<p>Using functional programming (FP) in enterprise software development is often quite a challenge. In this presentation, Sadek Drobi will talk about his experience of applying functional programming principles on a real-world project in relation with existing non-functional frameworks.
<p>In the year 2008 and just on the release of C# 3.0 and Linq, which is basically several FP concepts implemented on C# language, Sadek Drobi worked as a tech lead on a project where functional programming approach was used to meet performance requirements and to achieve desired response time. Facing similar issues, a mainstream architect would strive to instantiate less objects and to use mutation for optimization. Considering the big amount of data that had to be processed on each request, Sadek chose to do it otherwise: no mutation, used memorization, laziness, recursion, functions, curry, monads, list comprehensions and, then, parallelization to yield an almost purely functional core domain model.
<p>Sadek Drobi will talk more about this experience and elaborate on the good and the bad of going almost extreme through a functional programming approach from different perspectives.
<p>Participants don&#8217;t need to be functional programming experts even if having some knowledge about LinQ will spare you too much hard thinking during the session. Each new concept will be briefly introduced and the structure of the talk will be as non-sequential as possible so that its parts can be understood and analyzed separately.</p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/02/18/i-am-speaking-at-qcon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quiz:: SharpLight &#124;&gt; What does this do?</title>
		<link>http://sadekdrobi.com/2009/02/03/quiz-sharplight-what-does-this-do/</link>
		<comments>http://sadekdrobi.com/2009/02/03/quiz-sharplight-what-does-this-do/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 14:02:09 +0000</pubDate>
		<dc:creator>Sadache</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DOTNET]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[sharplight]]></category>

		<guid isPermaLink="false">http://sadekdrobi.com/2009/02/03/quiz-sharplight-what-does-this-do/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<p><a href="http://sadekdrobi.com/wp-content/uploads/2009/02/combination1.jpg"><img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" border="0" alt="combination" src="http://sadekdrobi.com/wp-content/uploads/2009/02/combination-thumb1.jpg" width="627" height="105" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sadekdrobi.com/2009/02/03/quiz-sharplight-what-does-this-do/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

