<?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>Rash thoughts about .NET, C#, F# and Dynamics NAV.</title>
	<atom:link href="http://www.navision-blog.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.navision-blog.de</link>
	<description>This Blog is about Microsoft Dynamics NAV (f.k.a Navision incl. C/SIDE and C/AL), C#, F# and .NET in general.</description>
	<lastBuildDate>Sun, 25 Mar 2012 18:34:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Statically typed access to JSON and XML by using schema inference</title>
		<link>http://www.navision-blog.de/2012/03/25/typed-access-to-json-and-xml/</link>
		<comments>http://www.navision-blog.de/2012/03/25/typed-access-to-json-and-xml/#comments</comments>
		<pubDate>Sun, 25 Mar 2012 18:11:46 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[type providers]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1163</guid>
		<description><![CDATA[I’m happy to annouce a new nuget release of FSharpx.TypeProviders. The new version 1.5.3 allows to access JSON and XML in a strongly typed way. These new type providers are based on an XML type provider by Tomas Petricek. I added a write API and a JSON version. Idea Whereas XML allows different ways to [...]]]></description>
			<content:encoded><![CDATA[<p>I’m happy to annouce a <a href="https://nuget.org/packages/FSharpx.TypeProviders">new nuget release of FSharpx.TypeProviders</a>. The new version 1.5.3 allows to access JSON and XML in a strongly typed way. These new type providers are based on an XML type provider by <a href="http://tomasp.net/">Tomas Petricek</a>. I added a write API and a JSON version. </p>
<h5>Idea</h5>
<p>Whereas XML allows different ways to define a schema, JSON has no schema. Nevertheless most documents have some kind of an implicitly defined schema. These new type providers try to infer the schema from a sample file and provide you types to access any file which is conform to this schema.</p>
<p>Let’s take a look at some of the new features.</p>
<h5>JSON access</h5>
<p>Consider this <a href="http://en.wikipedia.org/wiki/JSON">JSON sample from Wikipedia</a>:</p>
<p> <script src="https://gist.github.com/2197751.js"> </script>
<p>Let&#8217;s add this file to a new F# solution and reference the FSharpx.TypeProviders.dll via <em>install-package FSharpx.TypeProviders. </em>Now that we have a sample of the data we get full Intellisense:</p>
<p><a href="http://www.navision-blog.de/images/Typed-access-to-JSON-and-XML_FAB0/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Typed-access-to-JSON-and-XML_FAB0/image_thumb.png" width="504" height="281" /></a></p>
<p>In most cases you want to use the initial document only as a sample, therefore it’s also possible to load a different document at runtime which the type provider will treat with the same schema: <script src="https://gist.github.com/2197903.js"> </script><script src="https://gist.github.com/2197947.js"> </script>It&#8217;s even possible to modify properties: <script src="https://gist.github.com/2198014.js"> </script></p>
<h5>Accessing XML</h5>
<p>After adding a reference to System.Xml.dll and System.Xml.Linq.dll it&#8217;s also very easy to access XML. Since <strong>both type providers have the same features</strong> we will use yet another way to provide a schema sample. In this case we give the schema inlined: <script src="https://gist.github.com/2198449.js"> </script></p>
<h5>Schema invalidation</h5>
<p>One important aspect of type providers is the schema invalidation. For instance try to remove the line with the age property of WikiSample.txt and save the file. The type provider will detect this schema change and your code will no longer compile:</p>
<p><a href="http://www.navision-blog.de/images/Typed-access-to-JSON-and-XML_FAB0/image_3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Typed-access-to-JSON-and-XML_FAB0/image_thumb_3.png" width="504" height="254" /></a></p>
<p>Enjoy your statically typed JSON/XML documents.</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/03/25/typed-access-to-json-and-xml/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WPF Designer for F#</title>
		<link>http://www.navision-blog.de/2012/03/22/wpf-designer-for-f/</link>
		<comments>http://www.navision-blog.de/2012/03/22/wpf-designer-for-f/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 19:19:10 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[FSharpx]]></category>
		<category><![CDATA[type providers]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1154</guid>
		<description><![CDATA[F# 3.0 brings the new type providers feature which enables a lot of different applications. Today I’m happy to announce that the FSharpx project brings you a WPF designer for F# in the Visual Studio 11 beta. A big kudos to Johann Deneux for writing the underlying XAML type provider. Create a new F# 3.0 [...]]]></description>
			<content:encoded><![CDATA[<p>F# 3.0 brings the new <a href="http://msdn.microsoft.com/en-us/library/hh156509(v=vs.110).aspx">type providers</a> feature which enables a lot of different applications. Today I’m happy to announce that the <a href="https://github.com/fsharp/fsharpx">FSharpx project</a> brings you a WPF designer for F# in the Visual Studio 11 beta.</p>
<p><a href="http://www.navision-blog.de/images/WPF-Designer-for-F_EDC7/image.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/WPF-Designer-for-F_EDC7/image_thumb.png" width="504" height="316" /></a></p>
<p>A big kudos to <a href="http://sharp-gamedev.blogspot.de/">Johann Deneux</a> for writing the underlying <a href="https://github.com/fsharp/fsharpx/blob/master/src/FSharpx.TypeProviders/XamlProvider.fs">XAML type provider</a>.</p>
<ol>
<li>Create a new F# 3.0 Console application project </li>
<li>Set the output type to “Windows Application” in the project settings </li>
<li>Use nuget and <em>install-package FSharpx.TypeProviders</em> </li>
<li>Add references to WindowsBase.dll, PresentationFramework.dll, System.Xaml.dll and PresentationCore.dll </li>
<li>Add a Xaml file to your project. Something like this: <script src="https://gist.github.com/2161484.js"> </script></li>
<li>Now you can access the Xaml in a typed way: <script src="https://gist.github.com/2161552.js"> </script></li>
<li>Start the project </li>
</ol>
<p>Enjoy!</p>
<p>BTW: No code generation needed is for this. No more nasty *.xaml.cs files.    <br />BTW2: Try to change the name of Button1 in the Xaml and press save. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Zwinkerndes Smiley" src="http://www.navision-blog.de/images/WPF-Designer-for-F_112B0/wlEmoticon-winkingsmile.png" /></p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/03/22/wpf-designer-for-f/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Why do we need partial application? &#8211; Part 2 of n &#8211; Simulating type classes in C# and F#</title>
		<link>http://www.navision-blog.de/2012/01/31/why-do-we-need-partial-application-part-2-of-n-simulating-type-classes-in-c-and-f/</link>
		<comments>http://www.navision-blog.de/2012/01/31/why-do-we-need-partial-application-part-2-of-n-simulating-type-classes-in-c-and-f/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 16:48:58 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Currying]]></category>
		<category><![CDATA[partial  application]]></category>
		<category><![CDATA[type classes]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1149</guid>
		<description><![CDATA[This is yet another blog post in my Currying and Partial application series. This is what I have posted so far: Partial application in F# and C# Why do we need partial application? – Part 1 of n – Fluent interfaces and piping Currying and uncurrying in C# and F# In this post I want [...]]]></description>
			<content:encoded><![CDATA[<p>This is yet another blog post in my <a href="http://en.wikipedia.org/wiki/Currying">Currying</a> and <a href="http://en.wikipedia.org/wiki/Partial_application">Partial application</a> series. This is what I have posted so far:</p>
<ul>
<li><a href="http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/">Partial application in F# and C#</a> </li>
<li><a href="http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/">Why do we need partial application? – Part 1 of n – Fluent interfaces and piping</a> </li>
<li><a href="http://www.navision-blog.de/2012/01/30/currying-and-uncurrying-in-c-and-f/">Currying and uncurrying in C# and F#</a> </li>
</ul>
<p>In this post I want to show you a way to simulate <a href="http://en.wikipedia.org/wiki/Type_class">type classes</a> in C# and F#. Type classes are this wonderful feature in Haskell which allow you to specify constraints on your polymorphic types. We don’t have this in C# nor F#.</p>
<p>Let’s start with the following problem: We want to compute the sum of the squares of arbitrary numbers. We want to write something like this:</p>
<p><a href="http://www.navision-blog.de/images/Simulating-type-classes-in-C-and-F_F1D3/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Simulating-type-classes-in-C-and-F_F1D3/image_thumb.png" width="489" height="169" /></a></p>
<p>The problem is we don’t have a generic * function and of course we’d also need a generic + operator and maybe a generic zero. Obviously we need a constraint on the generic parameter T since + might not be defined for any type. So let’s define an interface for numbers:</p>
<p> <script src="https://gist.github.com/1711425.js"> </script>
<p>Nothing special here, so let&#8217;s get straight to the implementation for integers and doubles:</p>
<p> <script src="https://gist.github.com/1711433.js"> </script>
<p>So far so good. With this in our pocket we rewrite SumOfSquares() into this:</p>
<p> <script src="https://gist.github.com/1711443.js"> </script>
<p>The trick is that we pass the concrete implementation as the first parameter into our function. This works exactly like a type constraint or as <a href="http://research.microsoft.com/en-us/people/simonpj/">Simon Peyton-Jones</a> would say: the <a href="http://en.wikipedia.org/wiki/Virtual_method_table">vtable</a> travels into the function. Notice that we don’t have access to the definition of in nor double. There is no way for us to express that int or double implement a number interface.</p>
<p>Now let’s try this out:</p>
<p> <script src="https://gist.github.com/1711474.js"> </script>
<p>As you can see, this is perfectly type safe. We now have a way for poor man’s type classes in C#. Yay!</p>
<p>Now what has this to do with partial application? Let’s look at the same thing in F#:</p>
<p> <script src="https://gist.github.com/1711508.js"> </script>
<p>We&#8217;re using a lot of partial application here. Exercise: Try to spot all the places.</p>
<p>Ok, you’re right. This post might be a little bit far away from the partial application stuff, but it’s still related. Somehow.</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/01/31/why-do-we-need-partial-application-part-2-of-n-simulating-type-classes-in-c-and-f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Currying and uncurrying in C# and F#</title>
		<link>http://www.navision-blog.de/2012/01/30/currying-and-uncurrying-in-c-and-f/</link>
		<comments>http://www.navision-blog.de/2012/01/30/currying-and-uncurrying-in-c-and-f/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 17:00:29 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Currying]]></category>
		<category><![CDATA[partial  application]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1144</guid>
		<description><![CDATA[In the last couple of days I started to write some posts about Currying and Partial application: Partial application in F# and C# Why do we need partial application? – Part 1 of n – Fluent interfaces and piping This time I want to show you how we can write a higher-order function which allows [...]]]></description>
			<content:encoded><![CDATA[<p>In the last couple of days I started to write some posts about <a href="http://en.wikipedia.org/wiki/Currying">Currying</a> and <a href="http://en.wikipedia.org/wiki/Partial_application">Partial application</a>:</p>
<ul>
<li><a href="http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/">Partial application in F# and C#</a> </li>
<li><a href="http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/">Why do we need partial application? – Part 1 of n – Fluent interfaces and piping</a> </li>
</ul>
<p>This time I want to show you how we can write a <a href="http://en.wikipedia.org/wiki/Higher-order_function">higher-order function</a> which allows us to curry another function. Remember the multiplication function from the <a href="http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/">first post</a> and it’s curried form:</p>
<p> <script src="https://gist.github.com/1705219.js"> </script><br />
<h5>Currying</h5>
<p>The question is: how can we automate this transformation process? Remember we want to have the curryied form for partial application:<script src="https://gist.github.com/1705245.js"> </script></p>
<p>Let’s look at the signature of the desired Curry-function: in our case it has to take <font color="#333333"><strong>Func&lt;int, int, int&gt;</strong></font> and returns <font color="#333333"><strong>Func&lt;int, Func&lt;int, int&gt;&gt;</strong></font>. </p>
<p>If we generalize the <strong>ints</strong> to generic parameters and fix the signature then the implementation is trivial (Compiler Driven Programming). There is exactly one way to make this work:</p>
<p> <script src="https://gist.github.com/1705277.js"> </script>
<p>The F# implementation does exactly the same, but without all the annoying the type hints:</p>
<p> <script src="https://gist.github.com/1705298.js"> </script><br />
<h5>Uncurrying</h5>
<p>Of course you can undo the currying by applying a generic Uncurry-function:</p>
<p> <script src="https://gist.github.com/1705371.js"> </script><script src="https://gist.github.com/1705372.js"> </script>
<p>And in F# this looks like this:</p>
<p> <script src="https://gist.github.com/1705380.js"> </script><br />
<h5>Libraries</h5>
<p>Currying and Uncurrying are two very important concepts in functional programming so they are included in a couple of libraries:</p>
<ul>
<li>You can find it at the top of the <a href="https://github.com/fsharp/fsharpx/blob/master/src/FSharpx.Core/Prelude.fs">Prelude</a> in FSharpx (<a href="http://bugsquash.blogspot.com/2011/10/introducing-fsharpx.html">read more</a>). </li>
<li>You can find it in the <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html">Haskell Prelude</a>. </li>
<li>You can find similar functions in <a href="https://github.com/scalaz/scalaz">Scalaz</a>. </li>
<li>Adrian Lang wrote a library called <a href="https://github.com/adrianlang/partial-js">partial-js</a> which allows to do something similar in JavaScript. </li>
</ul>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/01/30/currying-and-uncurrying-in-c-and-f/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why do we need partial application? &#8211; Part 1 of n &#8211; Fluent interfaces and piping</title>
		<link>http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/</link>
		<comments>http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 10:34:35 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Currying]]></category>
		<category><![CDATA[partial  application]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1140</guid>
		<description><![CDATA[My last blog post was yet another introduction to Currying and Partial application. Now I want to put the focus more on the why part. Why do we want to have our functions in curryied form most of the time? This is the first part of a small blog post series and shows partial application [...]]]></description>
			<content:encoded><![CDATA[<p>My last <a href="http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/">blog post</a> was yet another introduction to <a href="http://en.wikipedia.org/wiki/Currying">Currying</a> and <a href="http://en.wikipedia.org/wiki/Partial_application">Partial application</a>. Now I want to put the focus more on the <font color="#333333"><strong>why</strong></font> part. Why do we want to have our functions in curryied form most of the time? This is the first part of a small blog post series and shows partial application in F# pipelines.</p>
<p>Using “<a href="http://en.wikipedia.org/wiki/Fluent_interface">Fluent interfaces</a>” is a popular technique to write code in a more readable form. In languages like C# they also provide a way to create the code much faster. On every . we get IntelliSense and this gives us a “fluid” way of writing.</p>
<p>Let’s consider the following task: we want to compute the sum of the square roots of all odd numbers between 1 and 100. In C# we can use the LINQ method chaining approach in order to do something like this:</p>
<p><a href="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_thumb.png" width="494" height="248" /></a></p>
<p>Now how does this look in F#? It’s basically the same. We replace every . with the |&gt; operator and use the analogous Seq.* functions:</p>
<p><a href="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_thumb_3.png" width="494" height="85" /></a></p>
<p>Oups! What happened here? The F# compiler noticed a type error. <strong>Math.Sqrt</strong> needs a float as input but we gave it an int. C# uses implicit casts between int and float so we didn’t noticed the problem there. Implicit casts are a little bit problematic, at least if you want to have proper <a href="http://en.wikipedia.org/wiki/Type_inference">type inference</a> so F# doesn’t have this feature. No problem, we are programmers so let’s add the conversion manually:</p>
<p> <script src="https://gist.github.com/1697997.js"> </script>
<p>Notice that <strong>float</strong> is a function from int to float and not a cast. </p>
<p>Now you might ask: how does this all relate to partial application? The answer is simple: In every pipeline step we use a higher-order function (Seq.*) and apply the first parameter with a lambda. The second parameter is given via the |&gt; operator from the line above.</p>
<p><a href="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_thumb_4.png" width="494" height="99" /></a></p>
<p>By applying our rule of thumb from the last post were are able to remove the x parameters:</p>
<p> <script src="https://gist.github.com/1698054.js"> </script>
<p>Now let’s step back to C#. Keeping this knowledge in mind we try to apply the same rule in order to get rid of the x parameters:</p>
<p><a href="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_5.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/ffe2881d8ffb_81AF/image_thumb_5.png" width="494" height="302" /></a></p>
<p>Oups again! Now we see same error in C#. In this case it doesn’t know how to apply the implicit cast. As I said they are “problematic”, but we know how to fix this:</p>
<p> <script src="https://gist.github.com/1698185.js"> </script></p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/01/29/why-do-we-need-partial-application-part-1-of-n-fluent-interfaces-and-piping/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Partial application in F# and C#</title>
		<link>http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/</link>
		<comments>http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 18:55:18 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Currying]]></category>
		<category><![CDATA[partial  application]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1128</guid>
		<description><![CDATA[Today I had a conversation on twitter about partial application and type inference in F#. Partial application is a very important and useful concept and there are a lot of resources out there. Here is a short list of related material: Uncovering the Unknown: Principles of Type Inference (video) Wikipedia: Currying, Partial application, Type inference [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had a conversation on twitter about partial application and type inference in F#. Partial application is a very important and useful concept and there are a lot of resources out there. Here is a short list of related material:</p>
<ul>
<li><a href="http://screencasts.chariotsolutions.com/webpage/uncovering-the-unknown-principles-of-type-inference-">Uncovering the Unknown: Principles of Type Inference (video)</a> </li>
<li>Wikipedia: <a href="http://en.wikipedia.org/wiki/Currying">Currying</a>, <a href="http://en.wikipedia.org/wiki/Partial_application">Partial application</a>, <a href="http://en.wikipedia.org/wiki/Type_inference">Type inference</a> </li>
<li>StackOverflow: <a href="http://stackoverflow.com/questions/218025/what-is-the-difference-between-currying-and-partial-application">What is the difference between currying and partial application</a> </li>
<li>HaskellWiki: <a href="http://www.haskell.org/haskellwiki/Partial_application">Partial application</a> </li>
<li><a href="http://www.navision-blog.de/2009/06/17/f-bootcamp-questions-and-answers-part-ii-currying/">F# BootCamp Q&amp;A on this blog</a> </li>
</ul>
<p>I promised to show a small sample and I hope this clarifies some of my points on twitter. Let&#8217;s consider a multiplication function in C#:</p>
<p> <script src="https://gist.github.com/1690023.js"> </script>
<p>This function allows us to compute the product of two ints. But what can I do when I need a function which doubles its input? The solutions is easy: I just create a new function:</p>
<p> <script src="https://gist.github.com/1690127.js"> </script>
<p>And when I need a function which triples its input? Same thing, just create another method. But can we do better?</p>
<p>Let’s transform the multiplication function into the curryied version. The transformation process is very easy once you see the pattern. It’s actually possible to write a function which curryies another function, but that’s something for another post. Anyway, here’s the curryied version:</p>
<p> <script src="https://gist.github.com/1690011.js"> </script>
<p>It&#8217;s a little bit noisy with all the funky Funcs, but Ok. We can still write the double function in terms of multiply:</p>
<p> <script src="https://gist.github.com/1690161.js"> </script>
<p>And of course we can use multiply directly (which might look a bit weird at first):</p>
<p> <script src="https://gist.github.com/1690171.js"> </script>
<p>But we can also use it in another way, which we couldn&#8217;t really do before:</p>
<p> <script src="https://gist.github.com/1690184.js"> </script>
<p>How cool is this? We just applied a single parameter and we got a new function without writing any method declarations. Unfortunately we wrote a lot of weird type declarations in order to get here, but hey.</p>
<p>Let’s move to a language which has type inference. Here’s the uncurryied version of multiply in F#:</p>
<p> <script src="https://gist.github.com/1690214.js"> </script>
<p>The type signature tells us, that we have to give it a tuple of ints and then we get an int back. That’s exactly the same as in C#. Notice that we think about x1,x2 as only one parameter – a tuple. How can we get to the curryied form? It couldn’t be easier: just remove the parentheses and you’re done:</p>
<p> <script src="https://gist.github.com/1690235.js"> </script>
<p>As you can see the type signature changes a little bit. The * is now just another arrow. This means we have basically the same as Func&lt;int, Func&lt;int, int&gt;&gt; but in a much nicer syntax. There is also another way to write this:</p>
<p> <script src="https://gist.github.com/1697880.js"> </script>
<p>This looks like the C# version, but notice how nicely the arrows align to the type signature. If we want to use the multiply function than we can write something like this:</p>
<p> <script src="https://gist.github.com/1690255.js"> </script>
<p>It’s also very easy to create partially applied functions:</p>
<p> <script src="https://gist.github.com/1690268.js"> </script>
<p>And finally the point which made me write this post. There is a simple rule: whenever we have the same parameter as the last parameter of the left and the right side of a function definition, we can remove it. This leads us to:</p>
<p> <script src="https://gist.github.com/1690298.js"> </script>
<p>Isn&#8217;t this beautiful?</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/01/27/partial-application-if-f-and-c/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>F# Legacy: Test implants</title>
		<link>http://www.navision-blog.de/2012/01/22/f-legacy-test-implants/</link>
		<comments>http://www.navision-blog.de/2012/01/22/f-legacy-test-implants/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 11:51:55 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Test Driven Design]]></category>
		<category><![CDATA[test implants]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1124</guid>
		<description><![CDATA[Legacy code is a problem in all languages, even F#. The super awesome Ilker Cetinkaya published an excellent article about “test implants”. I really recommend to read his post before you read this one. It’s a really well written story called “The quest of the test”. I destilled his nice little story to this small [...]]]></description>
			<content:encoded><![CDATA[<p>Legacy code is a problem in all languages, even F#. <img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Zwinkerndes Smiley" src="http://www.navision-blog.de/images/F-Legacy-Test-implants_AA75/wlEmoticon-winkingsmile.png" /></p>
<p>The super awesome <a href="http://ilker.de/about">Ilker Cetinkaya</a> published an excellent <a href="http://ilker.de/the-quest-of-the-test">article about “test implants”</a>. I really recommend to read his post before you read this one. It’s a really well written story called “<a href="http://ilker.de/the-quest-of-the-test">The quest of the test</a>”.</p>
<p>I destilled his nice little story to this small F# code:</p>
<p> <script src="https://gist.github.com/1656649.js"> </script>
<p>We have a function <strong><em>a</em></strong> that is part of a third-party API and a function <strong><em>b</em></strong> which is part of our own legacy code base. The problem is: we want to check that <strong><em>b</em></strong> has called <strong><em>a</em></strong>. without changing <strong><em>b</em></strong>’s signature. Ilker suggested to use a “test implant”. Let’s try to do something similar with our small F# code. Since we are in the land of functional programming our idea is to implant another function into <strong><em>b</em></strong>. So let’s rename <strong><em>b</em></strong> into <strong><em>b’</em></strong> and add the implant to the parameter list of <strong><em>b’</em></strong>.</p>
<p> <script src="https://gist.github.com/1656671.js"> </script>
<p>Of course we restore <strong><em>b</em></strong>’s behaviour by utilizing <strong><em>b’</em></strong>:</p>
<p> <script src="https://gist.github.com/1656674.js"> </script>
<p>As you can see, we didn’t change the signature nor the behaviour of <strong><em>b</em></strong>. This is a typical refactoring in F#. The program runs as before. Now we want to write our test:</p>
<p> <script src="https://gist.github.com/1656688.js"> </script>
<p>I hope you can see the similarity between this and Ilkers solution. The only difference is that we don’t use new constructors here. I really like this since it brings you one step further to nice functional design. What do you think?</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/01/22/f-legacy-test-implants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building FAKE scripts with Jenkins</title>
		<link>http://www.navision-blog.de/2012/01/16/building-fake-scripts-with-jenkins/</link>
		<comments>http://www.navision-blog.de/2012/01/16/building-fake-scripts-with-jenkins/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 16:11:26 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[FAKE - F# Make]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Jenkins]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/?p=1120</guid>
		<description><![CDATA[Jenkins is an extendable open source continuous integration server. In this blog post I show you how you can build FAKE’s Calculator sample with Jenkins. If you are familiar with Jenkins or Hudson then this should be straight forward. Install Jenkins Go to http://jenkins-ci.org/ and download/install Jenkins. In addition install the following plugins: Jenkins GIT [...]]]></description>
			<content:encoded><![CDATA[<p>Jenkins is an extendable open source continuous integration server. In this blog post I show you how you can build <a href="http://www.navision-blog.de/2009/04/01/getting-started-with-fake-a-f-sharp-make-tool/">FAKE’s Calculator</a> sample with Jenkins. If you are familiar with Jenkins or Hudson then this should be straight forward.</p>
<h5>Install Jenkins</h5>
<p>Go to <a href="http://jenkins-ci.org/">http://jenkins-ci.org/</a> and download/install Jenkins. In addition install the following plugins:</p>
<ul>
<li><a href="http://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin">Jenkins GIT plugin</a> </li>
<li><a href="http://wiki.jenkins-ci.org/display/JENKINS/NUnit+Plugin">Jenkins NUnit plugin</a> </li>
<li><a href="http://localhost:8080/pluginManager/wiki.jenkins-ci.org/display/JENKINS/Violations">Jenkins Violations plugin</a> </li>
</ul>
<h5>Create a new Task</h5>
<p>Create a new “free-style” task in Jenkins:</p>
<p><a href="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_thumb.png" width="504" height="185" /></a></p>
<p>Use git as the Source Control Management tool and configure the repo as following:</p>
<p><a href="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_thumb_3.png" width="494" height="458" /></a></p>
<p>Configure the build step to run FAKE from the command line:</p>
<p><a href="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_thumb_4.png" width="504" height="223" /></a></p>
<p>And finally configure the post build actions:</p>
<p><a href="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_5.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_thumb_5.png" width="504" height="281" /></a></p>
<h5>Running the build</h5>
<p>If everything is setup correctly, then you should be able to start the build from the project page:</p>
<p><a href="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_6.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_thumb_6.png" width="504" height="229" /></a></p>
<p>The output should look similar to this:</p>
<p><a href="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_7.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.navision-blog.de/images/Building-FAKE-scripts-with-Jenkins_EA4B/image_thumb_7.png" width="504" height="433" /></a></p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2012/01/16/building-fake-scripts-with-jenkins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Articles about FSharpx</title>
		<link>http://www.navision-blog.de/2011/10/19/articles-about-fsharpx/</link>
		<comments>http://www.navision-blog.de/2011/10/19/articles-about-fsharpx/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 14:49:34 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[FSharpx]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2011/10/19/articles-about-fsharpx/</guid>
		<description><![CDATA[My last posts described some special monads in F#. The code is now part of a new project called FSharpx. FSharpx is a library for the .NET platform implementing general functional constructs on top of the F# core library. The idea is that we start merging all these nice little F# open source projects we [...]]]></description>
			<content:encoded><![CDATA[<p>My last posts described <a href="http://www.navision-blog.de/2011/08/17/some-special-monads-in-f-part-5-of-n-application-poker/">some special monads in F#</a>. The code is now part of a new project called <a href="https://github.com/fsharp/fsharpx">FSharpx</a>. FSharpx is a library for the .NET platform implementing general functional constructs on top of the F# core library. The idea is that we start merging all these nice little F# open source projects we have and put them under one umbrella.</p>
<p>The project is in an early phase, but it’s really starting to accumulate so much interesting stuff and the number developers who are contributing is rising.</p>
<p>Unfortunately the documentation is not that good at the moment and therefore I want to present a collection of articles which cover some of the related topics:</p>
<ul>
<li><a href="http://bugsquash.blogspot.com/2011/10/introducing-fsharpx.html">Introducing FSharpx</a> by <a href="http://www.blogger.com/profile/15247972578064164206">Mauricio Scheffer</a></li>
<li><a href="http://bugsquash.blogspot.com/2011/10/10-reasons-to-use-f-runtime-in-your-c.html">10 reasons to use the F# runtime in your C# app</a> by <a href="http://www.blogger.com/profile/15247972578064164206">Mauricio Scheffer</a></li>
<li><a href="http://bugsquash.blogspot.com/2010/12/notes-on-haskell-functors-and-f.html">Functors</a> by <a href="http://www.blogger.com/profile/15247972578064164206">Mauricio Scheffer</a></li>
<li>Monads</li>
<ul>
<li><a href="http://www.navision-blog.de/2009/10/23/using-monads-in-fsharp-part-i-the-state-monad/">State-Monad</a></li>
<li><a href="http://www.navision-blog.de/2011/08/15/some-special-monads-in-f-part-2-of-n-undomonad/">Undo-Monad</a></li>
<li><a href="http://www.navision-blog.de/2011/08/15/some-special-monads-in-f-part-3-of-n-distributionmonad/">Distribution-Monad</a></li>
</ul>
<li><a href="http://wizardsofsmart.net/post/iteratee-in-f/">Iteratee</a> by <a href="http://wizardsofsmart.net/author/admin/">Ryan Riley</a></li>
<li><a href="http://dotnetslackers.com/articles/net/Programming-user-interfaces-using-f-sharp-workflows.aspx">Programming user interfaces using F# workflows</a> by <a href="http://tomasp.net/">Tomas Petricek</a></li>
<li><a title="http://bloggemdano.blogspot.com/2011/10/authoring-typeproviders-with.html" href="http://bloggemdano.blogspot.com/2011/10/authoring-typeproviders-with.html">Authoring Type Providers with the TypeProviderDSL from FSharpx</a> by <a href="http://www.blogger.com/profile/17462870714458080019">Dan Mohl</a></li>
<li><a title="http://bloggemdano.blogspot.com/2011/10/authoring-typeproviders-with.html" href="http://bloggemdano.blogspot.com/2011/09/simple-appsettings-type-provider.html">A Simple AppSettings Type Provider</a> by <a href="http://www.blogger.com/profile/17462870714458080019">Dan Mohl</a></li>
</ul>
<p>I also recommend you to checkout the <a href="https://github.com/fsharp/fsharpx/tree/master/tests">test projects</a>. You will find there a lot of interesting samples.</p>
<p>If you find more articles about FSharpx or related topics, then feel free to contact me. I will include them here and in the documentation of the project.</p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2011/10/19/articles-about-fsharpx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some special monads in F# &#8211; Part 5 of n &#8211; Application: Poker &#8211; Your chance to get rich!</title>
		<link>http://www.navision-blog.de/2011/08/17/some-special-monads-in-f-part-5-of-n-application-poker/</link>
		<comments>http://www.navision-blog.de/2011/08/17/some-special-monads-in-f-part-5-of-n-application-poker/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 08:52:07 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Informatik]]></category>
		<category><![CDATA[monad]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2011/08/17/some-special-monads-in-f-part-5-of-n-application-poker/</guid>
		<description><![CDATA[In the last part of this blog series I showed how we can utilize the DistributionMonad in order to solve the famous Monty Hall problem. This time I want to show you how we can use it to solve some basic Texas hold’em poker questions. We start by defining a model for poker in F#: [...]]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.navision-blog.de/2011/08/16/some-special-monads-in-f-part-4-of-n-application-the-monty-hall-problem/">last part of this blog series</a> I showed how we can utilize the <a href="http://www.navision-blog.de/2011/08/15/some-special-monads-in-f-part-3-of-n-distributionmonad/">DistributionMonad</a> in order to solve the famous <a href="http://en.wikipedia.org/wiki/Monty_Hall_problem">Monty Hall problem</a>. This time I want to show you how we can use it to solve some basic <a href="http://en.wikipedia.org/wiki/Texas_hold_%27em">Texas hold’em poker</a> questions.</p>
<p>We start by defining a model for poker in F#:</p>
<p> <script src="https://gist.github.com/1151080.js"> </script>
<p>As you can see we model cards as tuples of a rank and a suit. The complete deck is just a combination of all ranks with all suits.</p>
<p>Now we need some additional helpers for the DistributionMonad, which will allow us to draw cards from the deck. You can find further explanations about these helpers in the excellent paper by Martin Erwig and Steve Kollmansberger called <a href="http://web.engr.oregonstate.edu/~erwig/papers/PFP_JFP06.pdf">&quot;Functional Pearls: Probabilistic functional programming in Haskell&quot;</a>. Like the DistributionMonad itself, these helpers are already in the <a href="https://github.com/panesofglass/FSharp.Monad">FSharp.Monad</a> project and you get the bits from <a href="http://nuget.org/List/Packages/FSharp.Monad">nuget.org</a>.</p>
<p> <script src="https://gist.github.com/1151079.js"> </script>
<p>Now we are ready to perform our first query. Let&#8217;s see how we can compute the probability of drawing the Ace of Clubs and the Ace of Spades:</p>
<p> <script src="https://gist.github.com/1151108.js"> </script>
<p>But we can easily go a step further:</p>
<p> <script src="https://gist.github.com/1151121.js"> </script>
<p>If you keep this model in mind you might come up with a poker odds calculator on a smart phone. This might be your chance to get rich. <img src='http://www.navision-blog.de/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>&copy;2012 <a href="http://www.navision-blog.de">Rash thoughts about .NET, C#, F# and Dynamics NAV.</a>. All Rights Reserved.</p>.]]></content:encoded>
			<wfw:commentRss>http://www.navision-blog.de/2011/08/17/some-special-monads-in-f-part-5-of-n-application-poker/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

