<?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. &#187; F#</title>
	<atom:link href="http://www.navision-blog.de/tag/f/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>Wed, 14 Jul 2010 11:12:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>&#8220;FAKE &#8211; F# Make&#8221; 1.20.0 released</title>
		<link>http://www.navision-blog.de/2010/05/12/fake-f-make-1-20-0-released/</link>
		<comments>http://www.navision-blog.de/2010/05/12/fake-f-make-1-20-0-released/#comments</comments>
		<pubDate>Wed, 12 May 2010 12:26:43 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[FAKE - F# Make]]></category>
		<category><![CDATA[F-sharp Make]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2010/05/12/fake-f-make-1-20-0-released/</guid>
		<description><![CDATA[Today I released a new bugfix release for “FAKE – F# Make”. We fixed some path and logging issues and as a new feature we introduced the @@ operator which allows to combine paths. Download Repository &#169;2010 Rash thoughts about .NET, C#, F# and Dynamics NAV.. All Rights Reserved..]]></description>
			<content:encoded><![CDATA[<p>Today I released a new bugfix release for “FAKE – F# Make”. We fixed some path and logging issues and as a new feature we introduced the <a href="http://github.com/forki/FAKE/commit/540f8bc19b4a9dccecdee82ced779b7ac5036668">@@ operator</a> which allows to combine paths.</p>
<ul>
<li><a href="http://bitbucket.org/forki/fake/downloads">Download</a> </li>
<li><a href="http://github.com/forki/FAKE">Repository</a> </li>
</ul>
<p>&copy;2010 <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/2010/05/12/fake-f-make-1-20-0-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Generating an IObservable&lt;T&gt; from an IEvent in F#</title>
		<link>http://www.navision-blog.de/2009/11/24/generating-an-iobservablet-from-an-ievent-in-f/</link>
		<comments>http://www.navision-blog.de/2009/11/24/generating-an-iobservablet-from-an-ievent-in-f/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 11:39:29 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Reactive Framework]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2009/11/24/generating-an-iobservablet-from-an-ievent-in-f/</guid>
		<description><![CDATA[Yesterday I showed how we can map some of the Rx operators to an API which looks more like the F# base classes. Today I wanted to use these mapped operators in a WPF-application written in F#. F# gives us a nice way to use events as first class citizen (via IEvent) but these events [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I showed how we can <a href="http://www.navision-blog.de/2009/11/23/mapping-the-reactive-framework-rx-operators-for-f/">map some of the Rx operators to an API which looks more like the F# base classes</a>. Today I wanted to use these mapped operators in a WPF-application written in F#. </p>
<p>F# gives us a nice way to use events as first class citizen (via IEvent) but these events implement their own version of IObservable&lt;T&gt; (in FSharp.Core.dll), which is unfortunately incompatible with the Rx version and therefore with the mapped API.</p>
<p>The solution I found is to wrap the F# IEvent with a Rx IObservable&lt;T&gt;:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">/// Generates an observable from an IEvent</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> fromEvent (event:IEvent&lt;_,_&gt;) =&#160;&#160;&#160;&#160;&#160;&#160; </p>
<p style="margin: 0px">&#160; Observable.Create&lt;_&gt;(<span style="color: blue">fun</span> x <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; event.Subscribe x.OnNext |&gt; ignore</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">new</span> System.Action(<span style="color: blue">fun</span> () <span style="color: blue">-&gt;</span> ()))&#160;&#160;&#160;&#160;&#160; </p>
</p></div>
<p>Now we are able to use the WPF events as observables:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">// Register ListBox Commands</span></p>
<p style="margin: 0px">listBox1.KeyDown</p>
<p style="margin: 0px">&#160; |&gt; Observable.fromEvent</p>
<p style="margin: 0px">&#160; |&gt; Observable.filter (<span style="color: blue">fun</span> args <span style="color: blue">-&gt;</span> args.Key = Key.Delete)</p>
<p style="margin: 0px">&#160; |&gt; Observable.subscribe deleteElement</p>
</p></div>
<p>I am interested if someone has a different and maybe better solution to this problem.</p>
<p>Updated: 21.12.2009 – Observable.Context is no longer supported by Rx ==&gt; Removed</p>
<p>&copy;2010 <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/2009/11/24/generating-an-iobservablet-from-an-ievent-in-f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mapping the Reactive Framework (Rx) operators for F#</title>
		<link>http://www.navision-blog.de/2009/11/23/mapping-the-reactive-framework-rx-operators-for-f/</link>
		<comments>http://www.navision-blog.de/2009/11/23/mapping-the-reactive-framework-rx-operators-for-f/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 12:35:39 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[IObservable]]></category>
		<category><![CDATA[PLINQ]]></category>
		<category><![CDATA[Reactive Framework]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2009/11/23/mapping-the-reactive-framework-rx-operators-for-f/</guid>
		<description><![CDATA[The “Reactive Extensions for .NET (Rx)” comes with lot’s of operators for using IObservable&#60;T&#62;. This code mimics the signature of the default F# sequence combinators and allows to use observables like sequences. It is a similar approach like Matthews Podwysocki’s blog post about mapping the IParallelEnumerable. I will update this post from time to time [...]]]></description>
			<content:encoded><![CDATA[<p>The “<a href="http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx">Reactive Extensions for .NET (Rx)</a>” comes with lot’s of operators for using IObservable&lt;T&gt;. This code mimics the signature of the default F# sequence combinators and allows to use observables like sequences. It is a similar approach like Matthews Podwysocki’s blog post about <a href="http://weblogs.asp.net/podwysocki/archive/2009/02/23/adding-parallel-extensions-to-f.aspx">mapping the IParallelEnumerable</a>.</p>
<p>I will update this post from time to time to include more of the operators.</p>
<ul>
<li>Update: 25.11.2009 – new operators mapped </li>
<li>Update: 21.11.2009 – Updated to new Rx release </li>
</ul>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: blue">module</span> RxExtensions.Observable</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">open</span> System.Linq</p>
<p style="margin: 0px"><span style="color: blue">open</span> System</p>
<p style="margin: 0px"><span style="color: blue">open</span> System.Threading</p>
<p style="margin: 0px"><span style="color: blue">open</span> System.Windows.Threading</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">type</span> &#8216;a observable = IObservable&lt;&#8217;a&gt;</p>
<p style="margin: 0px"><span style="color: blue">type</span> &#8216;a observer = IObserver&lt;&#8217;a&gt;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// converts a lambda in a System.Action</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> asAction f = <span style="color: blue">new</span> System.Action(f)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// System.Action whichs does nothing</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> doNothing = asAction (<span style="color: blue">fun</span> () <span style="color: blue">-&gt;</span> ())</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Creates an observer</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> createObserver next error completed =</p>
<p style="margin: 0px">&#160; {<span style="color: blue">new</span> System.IObserver&lt;_&gt; <span style="color: blue">with</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; <span style="color: blue">member</span> this.OnCompleted() = completed()</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; <span style="color: blue">member</span> this.OnError(e) = error e</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; <span style="color: blue">member</span> this.OnNext(args) = next args}</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Creates a new observable </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> create f =</p>
<p style="margin: 0px">&#160; Observable.Create&lt;_&gt;(<span style="color: blue">fun</span> x <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; f x</p>
<p style="margin: 0px">&#160;&#160;&#160; doNothing)&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Creates a observable from a async</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> ofAsync async =</p>
<p style="margin: 0px">&#160; create</p>
<p style="margin: 0px">&#160;&#160;&#160; (<span style="color: blue">fun</span> obs <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160; Async.StartWithContinuations</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (async,obs.OnNext,obs.OnError,obs.OnError))</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Gets a dispatcher Schdeuler for the current dispatcher</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> getDispatcherScheduler _ = </p>
<p style="margin: 0px">&#160; <span style="color: blue">new</span> DispatcherScheduler(Dispatcher.CurrentDispatcher)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Generates an observable from an IEvent</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> fromEvent (event:IEvent&lt;_,_&gt;) = create (<span style="color: blue">fun</span> x <span style="color: blue">-&gt;</span> event.Add x.OnNext)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Generates an empty observable </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> empty&lt;&#8217;a&gt; = Observable.Empty&lt;&#8217;a&gt;() </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Takes the head of the elements</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> head = Observable.First </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Merges the two observables</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> mergeWith obs1 obs2 = Observable.Merge(obs2, obs1)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Merges all observables</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> mergeAll (observables:IObservable&lt;IObservable&lt;&#8217;a&gt;&gt;) = </p>
<p style="margin: 0px">&#160; Observable.Merge observables </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Merges all observables</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> merge (observables:(IObservable&lt;&#8217;a&gt;) seq) = </p>
<p style="margin: 0px">&#160; Observable.Merge observables </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Creates a range as an observable</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> range start count = Observable.Range(start, count)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Converts a seq in an observable</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> toObservable (seq: &#8216;a seq) = Observable.ToObservable seq</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Converts a observable in a seq</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> toEnumerable = Observable.ToEnumerable</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Subscribes to the Observable with all 3 callbacks</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> subscribeComplete next error completed (observable: &#8216;a observable) = </p>
<p style="margin: 0px">&#160;&#160; observable.Subscribe(</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; (<span style="color: blue">fun</span> x <span style="color: blue">-&gt;</span> next x), </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; (<span style="color: blue">fun</span> e <span style="color: blue">-&gt;</span> error e), </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; (<span style="color: blue">fun</span> () <span style="color: blue">-&gt;</span> completed()))</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Subscribes to the Observable with a</span></p>
<p style="margin: 0px"><span style="color: green">/// next and an error-function</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> subscribeWithError next error observable = </p>
<p style="margin: 0px">&#160; subscribeComplete next error (<span style="color: blue">fun</span> () <span style="color: blue">-&gt;</span> ()) observable</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Subscribes to the Observable with just a next-function</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> subscribe next observable = </p>
<p style="margin: 0px">&#160; subscribeWithError next ignore observable</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// throttles the observable for the given interval</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> throttle interval observable = </p>
<p style="margin: 0px">&#160; Observable.Throttle(observable,interval)&#160;&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// throttles the observable scheduled on the current dispatcher</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> throttleOnCurrentDispatcher interval observable = </p>
<p style="margin: 0px">&#160; Observable.Throttle(</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; observable,getDispatcherScheduler(),interval) </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// samples the observable at the given interval</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> sample interval observable = </p>
<p style="margin: 0px">&#160; Observable.Sample(observable,interval)&#160;&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// samples the observable at the given interval </span></p>
<p style="margin: 0px"><span style="color: green">/// scheduled on the current dispatcher</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> sampleOnCurrentDispatcher interval observable = </p>
<p style="margin: 0px">&#160; Observable.Sample(</p>
<p style="margin: 0px">&#160;&#160;&#160; observable,getDispatcherScheduler(),interval) </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// returns the observable sequence that reacts first.</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> takeFirstOf2Reactions obs1 obs2 = </p>
<p style="margin: 0px">&#160; Observable.Amb(obs1,obs2)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// returns the observable sequence that reacts first.</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> amb (obs: IObservable&lt;&#8217;a&gt; seq) = </p>
<p style="margin: 0px">&#160; Observable.Amb obs&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// returns the observable sequence that reacts first.</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> takeFirstReaction (obs: IObservable&lt;&#8217;a&gt; seq) = </p>
<p style="margin: 0px">&#160; Observable.Amb obs&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Matches when both observable sequences </span></p>
<p style="margin: 0px"><span style="color: green">/// have an available value. </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> both obs1 obs2 = Observable.And(obs1,obs2)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Merges two observable sequences</span></p>
<p style="margin: 0px"><span style="color: green">/// into one observable sequence.</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> zip obs1 obs2 =&#160;&#160;&#160; </p>
<p style="margin: 0px">&#160;&#160; Observable.Zip(obs1, obs2, Func&lt;_,_,_&gt;(<span style="color: blue">fun</span> a b <span style="color: blue">-&gt;</span> a, b))</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Merges two observable sequences into one observable sequence </span></p>
<p style="margin: 0px"><span style="color: green">/// whenever one of the observable sequences has a new value.</span></p>
<p style="margin: 0px"><span style="color: green">///&#160;&#160;&#160; ==&gt; More results than zip</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> combineLatest obs1 obs2 =&#160;&#160;&#160; </p>
<p style="margin: 0px">&#160;&#160; Observable.CombineLatest(</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; obs1, obs2, Func&lt;_,_,_&gt;(<span style="color: blue">fun</span> a b <span style="color: blue">-&gt;</span> a, b))&#160;&#160;&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Concats the two observables to one observable</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> concat observable = </p>
<p style="margin: 0px">&#160; Observable.SelectMany(</p>
<p style="margin: 0px">&#160;&#160;&#160; observable,</p>
<p style="margin: 0px">&#160;&#160;&#160; Func&lt;_,_&gt;(<span style="color: blue">fun</span> (x:IObservable&lt;&#8217;a&gt;) <span style="color: blue">-&gt;</span> x)) </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// maps the given observable with the given function</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> map f observable = </p>
<p style="margin: 0px">&#160; Observable.Select(observable,Func&lt;_,_&gt;(f))&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// maps the given observable with the given function</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> mapi f observable = </p>
<p style="margin: 0px">&#160; Observable.Select(observable,Func&lt;_,_,_&gt;(<span style="color: blue">fun</span> x i <span style="color: blue">-&gt;</span>f i x))&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Filters all elements where the given predicate is satified</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> filter f observable = </p>
<p style="margin: 0px">&#160; Observable.Where(observable, Func&lt;_,_&gt;(f)) </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Splits the observable into two observables</span></p>
<p style="margin: 0px"><span style="color: green">/// Containing the elements for which the predicate returns</span></p>
<p style="margin: 0px"><span style="color: green">/// true and false respectively</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> partition predicate observable =</p>
<p style="margin: 0px">&#160; filter predicate observable,</p>
<p style="margin: 0px">&#160; filter (predicate &gt;&gt; not) observable</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Skips n elements</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> skip n observable = Observable.Skip(observable, n)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Skips elements while the predicate is satisfied</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> skipWhile f observable = </p>
<p style="margin: 0px">&#160; Observable.SkipWhile(observable, Func&lt;_,_&gt;(f)) </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Runs all observable sequences in parallel </span></p>
<p style="margin: 0px"><span style="color: green">/// and combines their first values. </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> forkJoin (observables: (&#8216;a observable) seq) =</p>
<p style="margin: 0px">&#160; Observable.ForkJoin observables</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Counts the elements</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> length = Observable.Count</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Takes n elements</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> take n observable =</p>
<p style="margin: 0px">&#160; Observable.Take(observable, n)&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Determines whether the given observable is empty&#160; </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> isEmpty observable = Observable.IsEmpty observable</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Determines whether the given observable is not empty&#160; </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> isNotEmpty observable = not (Observable.IsEmpty observable)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Determines whether an observable sequence </span></p>
<p style="margin: 0px"><span style="color: green">/// contains a specified value</span></p>
<p style="margin: 0px"><span style="color: green">/// which satisfies the given predicate</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> exists predicate observable =</p>
<p style="margin: 0px">&#160; observable</p>
<p style="margin: 0px">&#160;&#160;&#160; |&gt; skipWhile (predicate &gt;&gt; not)</p>
<p style="margin: 0px">&#160;&#160;&#160; |&gt; isNotEmpty</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Continues an observable sequence that is terminated </span></p>
<p style="margin: 0px"><span style="color: green">/// by an exception with the next observable sequence. </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> catch (newObservable:IObservable&lt;&#8217;a&gt;) failingObservable = </p>
<p style="margin: 0px">&#160; Observable.Catch(failingObservable,newObservable)&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Takes elements while the predicate is satisfied</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> takeWhile f observable = </p>
<p style="margin: 0px">&#160; Observable.TakeWhile(observable, Func&lt;_,_&gt;(f)) </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Iterates through the observable </span></p>
<p style="margin: 0px"><span style="color: green">/// and performs the given side-effect</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> perform f observable =</p>
<p style="margin: 0px">&#160; Observable.Do(observable,<span style="color: blue">fun</span> x <span style="color: blue">-&gt;</span> f x)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Invokes finallyAction after source observable </span></p>
<p style="margin: 0px"><span style="color: green">/// sequence terminates normally or by an exception. </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> performFinally f observable =</p>
<p style="margin: 0px">&#160; Observable.Finally(observable,<span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> f())</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Folds the observable</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> fold f seed observable = </p>
<p style="margin: 0px">&#160; Observable.Aggregate(observable, seed, Func&lt;_,_,_&gt;(f))&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Retruns an observable from a async pattern&#160; </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> fromAsync beginF endF =</p>
<p style="margin: 0px">&#160;&#160; Observable.FromAsyncPattern&lt;_&gt;(</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; Func&lt;_,_,_&gt;(<span style="color: blue">fun</span> x y <span style="color: blue">-&gt;</span> beginF(x,y)),</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160; (<span style="color: blue">fun</span> x <span style="color: blue">-&gt;</span> endF x)).Invoke()</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">/// Runs all observable sequences in parallel </span></p>
<p style="margin: 0px"><span style="color: green">/// and combines their first values. </span></p>
<p style="margin: 0px"><span style="color: blue">let</span> subscribeAll next observables =</p>
<p style="margin: 0px">&#160; observables |&gt; Seq.map (subscribe next) |&gt; Seq.toList&#160;&#160;&#160;&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">type</span> IObservable&lt;&#8217;a&gt; <span style="color: blue">with</span></p>
<p style="margin: 0px">&#160; <span style="color: green">/// Subscribes to the Observable with just a next-function</span></p>
<p style="margin: 0px">&#160; <span style="color: blue">member</span> this.Subscribe(next) = </p>
<p style="margin: 0px">&#160;&#160;&#160; subscribe next this</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160; <span style="color: green">/// Subscribes to the Observable with a next </span></p>
<p style="margin: 0px">&#160; <span style="color: green">/// and an error-function</span></p>
<p style="margin: 0px">&#160; <span style="color: blue">member</span> this.Subscribe(next,error) = </p>
<p style="margin: 0px">&#160;&#160;&#160; subscribeWithError next error this</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160; <span style="color: green">/// Subscribes to the Observable with all 3 callbacks</span></p>
<p style="margin: 0px">&#160; <span style="color: blue">member</span> this.Subscribe(next,error,completed) = </p>
<p style="margin: 0px">&#160;&#160;&#160; subscribeComplete next error completed this</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">open</span> System.Net</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">type</span> WebRequest <span style="color: blue">with</span></p>
<p style="margin: 0px">&#160; <span style="color: blue">member</span> this.GetRequestStreamAsync() =</p>
<p style="margin: 0px">&#160;&#160;&#160; fromAsync </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; this.BeginGetRequestStream </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160; this.EndGetRequestStream</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160; <span style="color: blue">member</span> this.GetResponseAsync() =</p>
<p style="margin: 0px">&#160;&#160;&#160; fromAsync </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; this.BeginGetResponse </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; this.EndGetResponse </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160; <span style="color: blue">member</span> this.GetResponseStreamAsync() =</p>
<p style="margin: 0px">&#160;&#160;&#160; fromAsync </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; this.BeginGetRequestStream </p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; this.EndGetRequestStream</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: blue">type</span> Async&lt;&#8217;a&gt; <span style="color: blue">with</span></p>
<p style="margin: 0px">&#160; <span style="color: blue">member</span> this.ToObservable() = ofAsync this</p>
</p></div>
<p>&copy;2010 <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/2009/11/23/mapping-the-reactive-framework-rx-operators-for-f/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>&#8220;FAKE &#8211; F# Make&#8221; Version 0.10 released</title>
		<link>http://www.navision-blog.de/2009/10/06/fake-fsharp_make_version_0_10_released/</link>
		<comments>http://www.navision-blog.de/2009/10/06/fake-fsharp_make_version_0_10_released/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 09:59:10 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[FAKE - F# Make]]></category>
		<category><![CDATA[F-sharp Make]]></category>
		<category><![CDATA[Fake]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2009/10/06/fake-fsharp_make_version_0_10_released/</guid>
		<description><![CDATA[I just released a new version of my Open Source Build Automation Framework “FAKE – F# Make”. You can read more about FAKE on the project website or in the Getting started with &#34;FAKE &#8211; F# Make&#34;-article. Although the new release contains many bugfixes, I only want to show the two major improvements here. 1. [...]]]></description>
			<content:encoded><![CDATA[<p>I just released a new version of my Open Source Build Automation Framework <a href="http://code.google.com/p/fake/">“FAKE – F# Make”</a>. You can read more about FAKE on the <a href="http://code.google.com/p/fake/">project website</a> or in the <a href="http://www.navision-blog.de/2009/04/01/getting-started-with-fake-a-f-sharp-make-tool/">Getting started with &quot;FAKE &#8211; F# Make&quot;</a>-article.</p>
<p>Although the new release contains many bugfixes, I only want to show the two major improvements here.</p>
<h4>1. FAKE 0.10 uses FSI instead of FSC</h4>
<p>From now on FAKE uses the “F# Interactive” (fsi.exe) instead of the F# Compiler (fsc.exe) to run the build scripts, which brings two major improvements.</p>
<h5>No TempPath for compiled binaries needed</h5>
<p>Due to the fact that FAKE scripts are no longer compiled at the beginning of the build process, we don’t need a temporary folder for the created binaries. </p>
<h5>Loading modules at runtime</h5>
<p>The <font color="#0080ff">#load</font> command in F# scripts allows us to load modules at runtime. Now we are able to put reusable Targets or TargetTemplates (see below) into external build script files.</p>
<h4>2. TargetTemplates</h4>
<p>TargetTemplates provide an easy way to reuse common Targets. Let’s consider a (very) small sample:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px">Target <span style="color: maroon">&quot;TraceHello&quot;</span> (<span style="color: blue">fun</span> () <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160; trace <span style="color: maroon">&quot;Hello World from FAKE&quot;</span></p>
<p style="margin: 0px">)</p>
</p></div>
<p>This Target “TraceHello” traces a “Hello World” string into our build log. Now we want it to be slightly more generic and to trace a custom string. We can do this by using a TargetTemplate: </p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">/// createTraceTarget: string -&gt; string -&gt; Target</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> createTraceTarget = TargetTemplate (<span style="color: blue">fun</span> s <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160; trace s</p>
<p style="margin: 0px">)</p>
</p></div>
<p>Now we have a template (or a function which generates targets) that gets a string for the target name and a string for the trace text and generates&#160; a usable target:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px">createTraceTarget <span style="color: maroon">&quot;TraceHello&quot;</span> <span style="color: maroon">&quot;Hello World from FAKE&quot;</span></p>
<p style="margin: 0px">createTraceTarget <span style="color: maroon">&quot;Trace2&quot;</span> <span style="color: maroon">&quot;Trace another text&quot;</span></p>
</p></div>
<p>Of course the TargetTemplate function is generic and can be used with any tuple as parameter:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">/// createTraceTarget: string -&gt; string*int -&gt; Target</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> createTraceTarget = TargetTemplate (<span style="color: blue">fun</span> (s,d) <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160; trace s</p>
<p style="margin: 0px">&#160; trace &lt;| sprintf <span style="color: maroon">&quot;my int: %d&quot;</span> d</p>
<p style="margin: 0px">)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">createTraceTarget <span style="color: maroon">&quot;TraceHello&quot;</span> (<span style="color: maroon">&quot;Hello World from FAKE&quot;</span>,2)</p>
<p style="margin: 0px">createTraceTarget <span style="color: maroon">&quot;Trace2&quot;</span> (<span style="color: maroon">&quot;Trace another text&quot;</span>,42)</p>
</p></div>
<p>&copy;2010 <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/2009/10/06/fake-fsharp_make_version_0_10_released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting started with &#8220;FAKE &#8211; F# Make&#8221; &#8211; Get rid of the noise in your build scripts.</title>
		<link>http://www.navision-blog.de/2009/04/01/getting-started-with-fake-a-f-sharp-make-tool/</link>
		<comments>http://www.navision-blog.de/2009/04/01/getting-started-with-fake-a-f-sharp-make-tool/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 19:02:30 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[English posts]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[FAKE - F# Make]]></category>
		<category><![CDATA[Informatik]]></category>
		<category><![CDATA[NaturalSpec]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[F-sharp Make]]></category>
		<category><![CDATA[Fake]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[NAnt]]></category>
		<category><![CDATA[Rake]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2009/04/01/getting-started-with-fake-a-f-sharp-make-tool/</guid>
		<description><![CDATA[In this tutorial I will describe how you can set up a complete build infrastructure with “FAKE – F# Make”. You will learn: How to automatically compile your C# or F# projects How to automatically run NUnit UnitTests on your projects How to zip the output to a deployment folder Install F# “FAKE – F# [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I will describe how you can set up a complete build infrastructure with “<a href="http://code.google.com/p/fake/">FAKE – F# Make</a>”. You will learn:</p>
<ul>
<li>How to automatically compile your C# or F# projects </li>
<li>How to automatically run <a href="http://www.nunit.org/index.php?p=home">NUnit</a> UnitTests on your projects </li>
<li>How to zip the output to a deployment folder </li>
</ul>
<h5>Install F#</h5>
<p>“FAKE – F# Make” is completely written in <a href="http://en.wikipedia.org/wiki/F_Sharp_programming_language">F#</a> and all build scripts will also be written in F#, but this doesn’t imply you have to learn programming in F#. In fact the “FAKE – F# Make” syntax is very easy to learn. But if you need to you can use the complete power of F# and the .NET Framework.</p>
<p>But in order to get things working we need to install the F# environment. You can download the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=444005fb-e627-4feb-b51d-13d6a3b4b8ed&amp;displaylang=en">F# April 2010 CTP</a> from the <a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx">Microsoft F# Developer Center</a> or install Visual Studio 2010.</p>
<h5>Download Calculator Sample</h5>
<p>Now download the latest CalculatorSample-*.zip from the <a title="http://code.google.com/p/fake/downloads/list" href="http://bitbucket.org/forki/fake/downloads/">FAKE Download site</a>. This sample includes 3 tiny projects and basically the following structure:</p>
<ul>
<li>src\app
<ul>
<li>Calculator (Command line) </li>
<li>CalculatorLib (Class library) </li>
</ul>
</li>
<li>src\test
<ul>
<li>Test.CalculatorLib (NUnit test library) </li>
</ul>
</li>
<li>tools
<ul>
<li>FAKE Assemblies </li>
<li>NUnit </li>
</ul>
</li>
<li>build.bat </li>
<li>build.fsx </li>
<li>completeBuild.bat </li>
<li>completeBuild.fsx </li>
<li>Calculator.sln </li>
</ul>
<h5>Getting “FAKE – F# Make” started</h5>
<p>Open the file <em>tools\FAKE\FakeLib.dll.config</em> and check if the default configuration matches your system environment:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml</span><span style="color: blue"> </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot;<span style="color: blue"> </span><span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot;<span style="color: blue">?&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&lt;</span><span style="color: #a31515">configuration</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;</span><span style="color: #a31515">appSettings</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">add</span><span style="color: blue"> </span><span style="color: red">key</span><span style="color: blue">=</span>&quot;<span style="color: blue">MSBuildPath</span>&quot;<span style="color: blue"> </span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160;&#160;&#160; </span><span style="color: red">value</span><span style="color: blue">=</span>&quot;<span style="color: blue">c:\Windows\Microsoft.NET\Framework\v4.0.30319\</span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">add</span><span style="color: blue"> </span><span style="color: red">key</span><span style="color: blue">=</span>&quot;<span style="color: blue">FSIPath</span>&quot;<span style="color: blue"> </span></p>
<p style="margin: 0px"><span style="color: blue"></span><span style="color: red">&#160;&#160;&#160;&#160;&#160; value</span><span style="color: blue">=</span>&quot;<span style="color: blue">[ProgramFiles]\FSharp-2.0.0.0\bin\</span>&quot;<span style="color: blue"> /&gt;</span></p>
<p style="margin: 0px"><span style="color: blue">&#160; &lt;/</span><span style="color: #a31515">appSettings</span><span style="color: blue">&gt;</span></p>
<p style="margin: 0px">
<p style="margin: 0px"><span style="color: blue"></span></p>
<p>     <span style="color: blue">&lt;/</span><span style="color: #a31515">configuration</span><span style="color: blue">&gt;</span></p>
</p></div>
<p>If you run the build.bat from the command line then your first FAKE script (build.fsx) will be executed. If everything works fine you will get the following output:</p>
<p><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="bordered" title="Hello World from FAKE" border="0" alt="Hello World from FAKE" src="http://www.navision-blog.de/images/GettingstartedwithFAKEFMake_C1BC/image.png" width="500" height="185" /></p>
<p>Now open the <em>build.fsx</em> with Visual Studio. It should look like this:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">// include Fake libs</span></p>
<p style="margin: 0px"><span style="color: blue">#I</span> <span style="color: maroon">@&quot;tools\FAKE&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">#r</span> <span style="color: maroon">&quot;FakeLib.dll&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">open</span> Fake</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Default target</span></p>
<p style="margin: 0px">Target? Default &lt;-</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">fun</span> _ –<span style="color: blue">&gt; </span>trace <span style="color: maroon">&quot;Hello World from FAKE&quot;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// start build</span></p>
<p style="margin: 0px">Run? Default</p>
</p></div>
<p>As you can see the code is really simple. The very first lines include the FAKE libraries and are vital in all FAKE build scripts.</p>
<p>After this header the <em>Default</em> target is defined. A target definition contains of two important parts. The first is the name of the target (here “Default”) and the second is an action (here a simple trace of “Hello world”). Action can be defined as lambda expressions or methods.</p>
<p>The last line runs the “Default” target &#8211; which means it executes the defined action.</p>
<h5>Cleaning the last build output</h5>
<p>A typical first step in nearly every build scenario is to clean the output of the last build. We can achieve this by modifying the <em>build.fsx</em> to the following:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">// include Fake libs</span></p>
<p style="margin: 0px"><span style="color: blue">#I</span> <span style="color: maroon">@&quot;tools\FAKE&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">#r</span> <span style="color: maroon">&quot;FakeLib.dll&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">open</span> Fake</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Properties</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> buildDir = <span style="color: maroon">@&quot;.\build\&quot;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Targets</span></p>
<p style="margin: 0px">Target? Clean &lt;-</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> CleanDir buildDir</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? Default &lt;-</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> trace <span style="color: maroon">&quot;Hello World from FAKE&quot;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Dependencies</span></p>
<p style="margin: 0px">For? Default &lt;- Dependency? Clean</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// start build</span></p>
<p style="margin: 0px">Run? Default</p>
</p></div>
<p>We introduced some new concepts in this snippet. At first we defined a global property called “buildDir” with the relative path of a temporary build folder.</p>
<p>In the <em>Clean</em> target we want the CleanDir task to clean up this build directory. This simply deletes all files in the folder or creates the directory if necessary.</p>
<p>In the dependencies section we say that the Default target is dependent of the Clean target. In other words Clean is a prerequisite of Default and will be run before the execution of Default:</p>
<p><a href="http://www.navision-blog.de/images/GettingstartedwithFAKEFMakeGetridofthen_10682/image.png"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="bordered" title="Clean is a dependency of Default" border="0" alt="Clean is a dependency of Default" src="http://www.navision-blog.de/images/GettingstartedwithFAKEFMakeGetridofthen_10682/image_thumb.png" width="378" height="185" /></a>&#160;</p>
<h5>Building the application</h5>
<p>In the next step we want to compile our application libraries, which means we want to compile all projects under /src/app with MSBuild.</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">// include Fake libs</span></p>
<p style="margin: 0px"><span style="color: blue">#I</span> <span style="color: maroon">@&quot;tools\FAKE&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">#r</span> <span style="color: maroon">&quot;FakeLib.dll&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">open</span> Fake</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Properties</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> buildDir = <span style="color: maroon">@&quot;.\build\&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> appReferences = Scan (!+ <span style="color: maroon">@&quot;src\app\**\*.csproj&quot;</span>)</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Targets</span></p>
<p style="margin: 0px">Target? Clean &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> CleanDir buildDir</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? BuildApp &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> target = <span style="color: maroon">&quot;Build&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: green">// compile all projects below src/app/ in Release mode</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> apps = MSBuildRelease buildDir target appReferences</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: green">// log the output files</span></p>
<p style="margin: 0px">&#160;&#160;&#160; Log <span style="color: maroon">&quot;AppBuild-Output: &quot;</span> apps</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? Default &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> trace <span style="color: maroon">&quot;Hello World from FAKE&quot;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Dependencies</span></p>
<p style="margin: 0px">For? BuildApp &lt;- Dependency? Clean</p>
<p style="margin: 0px">For? Default &lt;- Dependency? BuildApp</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// start build</span></p>
<p style="margin: 0px">Run? Default</p>
</p></div>
<p>Again, we defined a new build target named “BuildApp” which compiles all project files given in the property appReferences with the MSBuild task. The output will be copied to <em>buildDir</em>.</p>
<p>In order to find the right project files “FAKE – F# Make” scans the folder src/app/ and all subfolders with the given pattern. Therefore a similar FileSet definition like in NAnt or MSBuild (see <a href="http://code.google.com/p/fake/">project page</a> for details) is used.</p>
<p>In addition the target dependencies are modified. Now Default is dependent of BuildApp and BuildApp needs Clean as a prerequisite.</p>
<p>This means the execution order is: Clean ==&gt; BuildApp ==&gt; Default.</p>
<p><a href="http://www.navision-blog.de/images/GettingstartedwithFAKEFMakeGetridofthen_10682/image_3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="App-Build output" border="0" alt="App-Build output" src="http://www.navision-blog.de/images/GettingstartedwithFAKEFMakeGetridofthen_10682/image_thumb_3.png" width="470" height="222" /></a>&#160;</p>
<h5>Building Test projects</h5>
<p>Now our main application will be built automatically and it’s time to build the test application. We use pretty the same concepts as before:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">// include Fake libs</span></p>
<p style="margin: 0px"><span style="color: blue">#I</span> <span style="color: maroon">@&quot;tools\FAKE&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">#r</span> <span style="color: maroon">&quot;FakeLib.dll&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">open</span> Fake</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Properties</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> buildDir = <span style="color: maroon">@&quot;.\build\&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> testDir&#160; = <span style="color: maroon">@&quot;.\test\&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> appReferences&#160; = !+ <span style="color: maroon">@&quot;src\app\**\*.csproj&quot;</span> |&gt; Scan</p>
<p style="margin: 0px"><span style="color: blue">let</span> testReferences = !+ <span style="color: maroon">@&quot;src\test\**\*.csproj&quot;</span> |&gt; Scan</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Targets</span></p>
<p style="margin: 0px">Target? Clean &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ –<span style="color: blue">&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; CleanDir buildDir</p>
<p style="margin: 0px">&#160;&#160;&#160; CleanDir testDir</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? BuildApp &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> target = <span style="color: maroon">&quot;Build&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: green">// compile all projects below src/app/ in Release mode</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> apps = MSBuildRelease buildDir target appReferences</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: green">// log the output files</span></p>
<p style="margin: 0px">&#160;&#160;&#160; Log <span style="color: maroon">&quot;AppBuild-Output: &quot;</span> apps</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? BuildTest &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> testApps = MSBuildDebug testDir <span style="color: maroon">&quot;Build&quot;</span> testReferences</p>
<p style="margin: 0px">&#160;&#160;&#160; Log <span style="color: maroon">&quot;TestBuild-Output: &quot;</span> testApps&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? Default &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> trace <span style="color: maroon">&quot;Hello World from FAKE&quot;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Dependencies</span></p>
<p style="margin: 0px">For? BuildApp &lt;- Dependency? Clean</p>
<p style="margin: 0px">For? BuildTest &lt;- Dependency? Clean</p>
<p style="margin: 0px">For? Default &lt;-</p>
<p style="margin: 0px">&#160;&#160;&#160; Dependency? BuildApp</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; |&gt; And? BuildTest</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// start build</span></p>
<p style="margin: 0px">Run? Default</p>
</p></div>
<p>This time we define a new target “BuildTest”, which compiles all C# projects below src/test/ in Debug mode and we mark the target as a dependency of Default.</p>
<p>As you can see the Clean target is now a dependency of BuildApp and BuildTest, since we also have to clean the test dir. Although the Clean target is referenced twice the “FAKE – F# Make” runtime ensures that it will only be executed once.</p>
<p>The execution order is now Clean ==&gt; BuildApp ==&gt; BuildTest ==&gt; Default.</p>
<h5>Testing the test assemblies with NUnit</h5>
<p>Now all our projects will be compiled and we can use the NUnit task in order to test our test assemblies:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">// include Fake libs</span></p>
<p style="margin: 0px"><span style="color: blue">#I</span> <span style="color: maroon">@&quot;tools\FAKE&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">#r</span> <span style="color: maroon">&quot;FakeLib.dll&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">open</span> Fake</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Properties</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> buildDir = <span style="color: maroon">@&quot;.\build\&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> testDir&#160; = <span style="color: maroon">@&quot;.\test\&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> appReferences&#160; = !+ <span style="color: maroon">@&quot;src\app\**\*.csproj&quot;</span> |&gt; Scan</p>
<p style="margin: 0px"><span style="color: blue">let</span> testReferences = !+ <span style="color: maroon">@&quot;src\test\**\*.csproj&quot;</span> |&gt; Scan</p>
<p style="margin: 0px"><span style="color: blue">let</span> testAssemblies = !+ (testDir + <span style="color: maroon">@&quot;\NUnit.Test.*.dll&quot;</span>) |&gt; Scan</p>
<p style="margin: 0px"><span style="color: blue">let</span> nunitPath = <span style="color: maroon">@&quot;.\Tools\NUnit\bin&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> nunitOutput = testDir + <span style="color: maroon">@&quot;TestResults.xml&quot;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Targets</span></p>
<p style="margin: 0px">Target? Clean &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; CleanDir buildDir</p>
<p style="margin: 0px">&#160;&#160;&#160; CleanDir testDir</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? BuildApp &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> target = <span style="color: maroon">&quot;Build&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: green">// compile all projects below src/app/ in Release mode</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> apps = MSBuildRelease buildDir target appReferences</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: green">// log the output files</span></p>
<p style="margin: 0px">&#160;&#160;&#160; Log <span style="color: maroon">&quot;AppBuild-Output: &quot;</span> apps</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? BuildTest &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> testApps = MSBuildDebug testDir <span style="color: maroon">&quot;Build&quot;</span> testReferences</p>
<p style="margin: 0px">&#160;&#160;&#160; Log <span style="color: maroon">&quot;TestBuild-Output: &quot;</span> testApps&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? Test &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; NUnit (<span style="color: blue">fun</span> p <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {p <span style="color: blue">with</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ToolPath = nunitPath;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DisableShadowCopy = <span style="color: blue">true</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; OutputFile = nunitOutput})</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; testAssemblies</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? Default &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> trace <span style="color: maroon">&quot;Hello World from FAKE&quot;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Dependencies</span></p>
<p style="margin: 0px">For? BuildApp &lt;- Dependency? Clean</p>
<p style="margin: 0px">For? BuildTest &lt;- Dependency? Clean</p>
<p style="margin: 0px">For? Test &lt;-</p>
<p style="margin: 0px">&#160;&#160;&#160; Dependency? BuildApp</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; |&gt; And? BuildTest</p>
<p style="margin: 0px">For? Default &lt;- Dependency? Test&#160;&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// start build</span></p>
<p style="margin: 0px">Run? Default</p>
</p></div>
<p>Our new target “Test” scans the test directory for test assemblies and runs them with NUnit. The mysterious part <strong>(fun p –&gt; …) </strong>simply overrides the default parameters of the NUnit task and allows to specify concrete parameters.</p>
<p>The execution order is now Clean ==&gt; BuildApp ==&gt; BuildTest ==&gt; Test ==&gt; Default.</p>
<p><a href="http://www.navision-blog.de/images/GettingstartedwithFAKEFMakeGetridofthen_10682/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Test output" border="0" alt="Test output" src="http://www.navision-blog.de/images/GettingstartedwithFAKEFMakeGetridofthen_10682/image_thumb_4.png" width="504" height="192" /></a></p>
<h5>Deploying a zip file</h5>
<p>Now we want to deploy a *.zip file containing our application:</p>
<div style="font-family: courier new; background: white; color: black; font-size: 10pt">
<p style="margin: 0px"><span style="color: green">// include Fake libs</span></p>
<p style="margin: 0px"><span style="color: blue">#I</span> <span style="color: maroon">@&quot;tools\FAKE&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">#r</span> <span style="color: maroon">&quot;FakeLib.dll&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">open</span> Fake</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Properties</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> buildDir = <span style="color: maroon">@&quot;.\build\&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> testDir&#160; = <span style="color: maroon">@&quot;.\test\&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> deployDir&#160; = <span style="color: maroon">@&quot;.\deploy\&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> appReferences&#160; = !+ <span style="color: maroon">@&quot;src\app\**\*.csproj&quot;</span> |&gt; Scan</p>
<p style="margin: 0px"><span style="color: blue">let</span> testReferences = !+ <span style="color: maroon">@&quot;src\test\**\*.csproj&quot;</span> |&gt; Scan</p>
<p style="margin: 0px"><span style="color: blue">let</span> testAssemblies = !+ (testDir + <span style="color: maroon">@&quot;\NUnit.Test.*.dll&quot;</span>) |&gt; Scan</p>
<p style="margin: 0px"><span style="color: blue">let</span> nunitPath = <span style="color: maroon">@&quot;.\Tools\NUnit\bin&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> nunitOutput = testDir + <span style="color: maroon">@&quot;TestResults.xml&quot;</span></p>
<p style="margin: 0px"><span style="color: blue">let</span> filesToZip = !+ (buildDir + <span style="color: maroon">&quot;\**\*.*&quot;</span>) &#8212; <span style="color: maroon">&quot;*.zip&quot;</span> |&gt; Scan</p>
<p style="margin: 0px"><span style="color: blue">let</span> zipFileName = deployDir + <span style="color: maroon">&quot;Calculator.zip&quot;</span></p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Targets</span></p>
<p style="margin: 0px">Target? Clean &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> CleanDirs [buildDir; testDir; deployDir]</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? BuildApp &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> target = <span style="color: maroon">&quot;Build&quot;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: green">// compile all projects below src/app/ in Release mode</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> apps = MSBuildRelease buildDir target appReferences</p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: green">// log the output files</span></p>
<p style="margin: 0px">&#160;&#160;&#160; Log <span style="color: maroon">&quot;AppBuild-Output: &quot;</span> apps</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? BuildTest &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; <span style="color: blue">let</span> testApps = MSBuildDebug testDir <span style="color: maroon">&quot;Build&quot;</span> testReferences</p>
<p style="margin: 0px">&#160;&#160;&#160; Log <span style="color: maroon">&quot;TestBuild-Output: &quot;</span> testApps&#160;&#160; </p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? Test &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160; NUnit (<span style="color: blue">fun</span> p <span style="color: blue">-&gt;</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {p <span style="color: blue">with</span></p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ToolPath = nunitPath;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DisableShadowCopy = <span style="color: blue">true</span>;</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; OutputFile = nunitOutput})</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; testAssemblies</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? Deploy &lt;-</p>
<p style="margin: 0px">&#160; <span style="color: blue">fun</span> _ <span style="color: blue">-&gt;</span> Zip buildDir zipFileName filesToZip</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px">Target? Default &lt;- DoNothing</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// Dependencies</span></p>
<p style="margin: 0px">For? BuildApp &lt;- Dependency? Clean</p>
<p style="margin: 0px">For? BuildTest &lt;- Dependency? Clean</p>
<p style="margin: 0px">For? Test &lt;-</p>
<p style="margin: 0px">&#160;&#160;&#160; Dependency? BuildApp</p>
<p style="margin: 0px">&#160;&#160;&#160;&#160;&#160; |&gt; And? BuildTest</p>
<p style="margin: 0px">For? Deploy &lt;- Dependency? Test</p>
<p style="margin: 0px">For? Default &lt;- Dependency? Deploy</p>
<p style="margin: 0px">&#160;</p>
<p style="margin: 0px"><span style="color: green">// start build</span></p>
<p style="margin: 0px">Run? Default</p>
</p></div>
<p>The new target “Deploy” scans the build directory for all files but zip-files. The result will be zipped to <em>\deploy\Calculator.zip</em> via the Zip task.</p>
<p>The execution order is now Clean ==&gt; BuildApp ==&gt; BuildTest ==&gt; Test ==&gt; Deploy ==&gt; Default whereas Default now is only used as a entry point.</p>
<h5></h5>
<h5>What’s next?</h5>
<p>Now your build file should look like <em>completeBuild.fsx</em> and you are ready to write your own “FAKE – F# Make” build scripts. If you have any questions or suggestions feel free to comment on this post.</p>
<p>In the <a href="http://www.navision-blog.de/2009/04/02/adding-fxcop-to-a-fake-build-script/">next article</a> I will show how we can add FxCop to our build in order to check specific naming rules.</p>
<p>&copy;2010 <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/2009/04/01/getting-started-with-fake-a-f-sharp-make-tool/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using PLINQ in F# – Parallel Map and Reduce (Fold) functions &#8211; part 1</title>
		<link>http://www.navision-blog.de/2008/10/23/using-plinq-in-fsharp-parallel-map-and-reduce-fold-functions/</link>
		<comments>http://www.navision-blog.de/2008/10/23/using-plinq-in-fsharp-parallel-map-and-reduce-fold-functions/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 16:25:37 +0000</pubDate>
		<dc:creator>Steffen Forkmann</dc:creator>
				<category><![CDATA[.NET 3.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Map and fold]]></category>
		<category><![CDATA[MapReduce]]></category>
		<category><![CDATA[Parallel Computing]]></category>
		<category><![CDATA[Parallel Extensions]]></category>
		<category><![CDATA[PLINQ]]></category>

		<guid isPermaLink="false">http://www.navision-blog.de/2008/10/23/using-plinq-in-f-parallel-map-and-fold-functions/</guid>
		<description><![CDATA[If your wondering how Google computes query results in such a short time you have to read the famous “MapReduce”-Paper by Jeffrey Dean and Sanjay Ghemawat (2004). It shows how one can split large tasks into a mapping and a reduce step which could then be processed in parallel. With PLINQ (part of the Parallel [...]]]></description>
			<content:encoded><![CDATA[<p>If your wondering how Google computes query results in such a short time you have to read the famous <a title="MapReduce: Simplified Data Processing on Large Clusters" href="http://labs.google.com/papers/mapreduce.html">“MapReduce”-Paper by Jeffrey Dean and Sanjay Ghemawat</a> (2004). It shows how one can split large tasks into a mapping and a reduce step which could then be processed in parallel.</p>
<p>With PLINQ (part of the <a href="http://msdn.microsoft.com/en-us/concurrency/default.aspx">Parallel Extensions to the .NET Framework</a>) you can easily use “MapReduce”-pattern in .NET and especially F#. PLINQ will take care of all the MultiThreading and load balancing stuff. You only have to give PLINQ a map and a reduce (or fold) function.</p>
<p>Lets consider a small example. Someone wants to compute the sum of the factorials of all integers from 1 to 3000. With <em>List.map</em> and <em>List.fold_left</em> this is a very easy task in F#:</p>
<div style="font-size: 10pt; background: white; color: black; font-family: courier new">
<pre style="margin: 0px"><span style="color: blue">#light</span></pre>
<pre style="margin: 0px"><span style="color: blue">open</span> System</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> add a b = a + b</pre>
<pre style="margin: 0px"><span style="color: blue">let</span> fac (x:bigint) = [1I..x] |&gt; List.fold_left (*) 1I</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><strong><span style="color: blue">let</span> sum =</strong></pre>
<pre style="margin: 0px"><strong>  [1I..3000I]</strong></pre>
<pre style="margin: 0px"><strong>    |&gt; List.map fac</strong></pre>
<pre style="margin: 0px"><strong>    |&gt; List.fold_left add 0I</strong></pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px">printfn <span style="color: maroon">"Sum of Factorials: %A"</span> sum</pre>
<pre style="margin: 0px"></pre>
</div>
<p>Of course you could do much much better if you don’t compute every factorial on its own (I will show this in one of the next parts) &#8211; but for this time I need an easy function that is time consuming.</p>
<p>This simple Task needs 27 sec. on my Core 2 Duo E6550 with 2.33 GHz and 3.5 GB RAM.</p>
<p>But we can do better if we use parallel map and fold functions with help of PLINQ:</p>
<div style="font-size: 10pt; background: white; color: black; font-family: courier new">
<pre style="margin: 0px"><span style="color: blue">let</span> pMap (mapF:'a <span style="color: blue">-&gt;</span> 'b) (data:IParallelEnumerable&lt;'a&gt;) =</pre>
<pre style="margin: 0px">  ParallelEnumerable.Select(data, mapF)</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> pFold foldF seed (data:IParallelEnumerable&lt;'a&gt;)=</pre>
<pre style="margin: 0px">  ParallelEnumerable.Aggregate&lt;'a,'b&gt;(</pre>
<pre style="margin: 0px">    data, seed, <span style="color: blue">new</span> Func&lt;'b,'a,'b&gt;(foldF))</pre>
</div>
<p>Now we can easily transform our calculation to a parallel version:</p>
<div style="font-size: 10pt; background: white; color: black; font-family: courier new">
<pre style="margin: 0px"><strong><span style="color: blue">let</span> sum =</strong></pre>
<pre style="margin: 0px"><strong>  [1I..3000I].AsParallel&lt;bigint&gt;()</strong></pre>
<pre style="margin: 0px"><strong>    |&gt; pMap fac </strong></pre>
<pre style="margin: 0px"><strong>    |&gt; pFold add 0I</strong></pre>
</div>
<p>Putting all together we can write a small test application:</p>
<div style="font-size: 10pt; background: white; color: black; font-family: courier new">
<pre style="margin: 0px"><span style="color: blue">#light </span></pre>
<pre style="margin: 0px"><span style="color: blue">open</span> System</pre>
<pre style="margin: 0px"><span style="color: blue">open</span> System.Linq</pre>
<pre style="margin: 0px"><span style="color: blue">open</span> System.Diagnostics</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> testRuntime f =</pre>
<pre style="margin: 0px">  <span style="color: blue">let</span> watch = <span style="color: blue">new</span> Stopwatch()</pre>
<pre style="margin: 0px">  watch.Start()</pre>
<pre style="margin: 0px">  (f(),watch.Elapsed)</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> add a b = a + b</pre>
<pre style="margin: 0px"><span style="color: blue">let</span> fac (x:bigint) = [1I..x] |&gt; List.fold_left (*) 1I</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> list = [1I..3000I]</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> pMap (mapF:'a <span style="color: blue">-&gt;</span> 'b) (data:IParallelEnumerable&lt;'a&gt;)=</pre>
<pre style="margin: 0px">  ParallelEnumerable.Select(data, mapF)</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> pFold foldF seed (data:IParallelEnumerable&lt;'a&gt;)=</pre>
<pre style="margin: 0px">  ParallelEnumerable.Aggregate&lt;'a,'b&gt;(</pre>
<pre style="margin: 0px">    data, seed, <span style="color: blue">new</span> Func&lt;'b,'a,'b&gt;(foldF))</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> PLINQ() =</pre>
<pre style="margin: 0px">  list.AsParallel&lt;bigint&gt;()</pre>
<pre style="margin: 0px">    |&gt; pMap fac</pre>
<pre style="margin: 0px">    |&gt; pFold add 0I</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> sequential() =</pre>
<pre style="margin: 0px">  list</pre>
<pre style="margin: 0px">   |&gt; List.map fac</pre>
<pre style="margin: 0px">   |&gt; List.fold_left add 0I</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> (sumSequential,timeSequential) =</pre>
<pre style="margin: 0px">  testRuntime sequential</pre>
<pre style="margin: 0px">printfn <span style="color: maroon">"Time Normal: %.3fs" </span>timeSequential.TotalSeconds</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px"><span style="color: blue">let</span> (sumPLINQ,timePLINQ) =</pre>
<pre style="margin: 0px">  testRuntime PLINQ</pre>
<pre style="margin: 0px">printfn <span style="color: maroon">"Time PLINQ: %.3fs"</span> timePLINQ.TotalSeconds</pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px">timePLINQ.TotalSeconds / timeSequential.TotalSeconds</pre>
<pre style="margin: 0px">  |&gt; printfn <span style="color: maroon">"Ratio: %.2f"</span></pre>
<pre style="margin: 0px"></pre>
<pre style="margin: 0px">sumSequential = sumPLINQ</pre>
<pre style="margin: 0px">  |&gt; printfn <span style="color: maroon">"Same Results: %A"</span></pre>
</div>
<p>On my machine I get the following results:</p>
<blockquote><p>Time Normal: 27.955s</p>
<p>Time PLINQ: 15.505s</p>
<p>Ratio: 0.55</p>
<p>Same Results: true</p></blockquote>
<p>This means I get nearly a perfect load balancing on my two processors for this task.</p>
<p>In <a href="http://www.navision-blog.de/2008/10/24/using-plinq-in-fsharp-parallel-map-and-reduce-fold-functions-part-ii/">part II</a> I describe how one can compute a series of functions in parallel.</p>
<p>&copy;2010 <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/2008/10/23/using-plinq-in-fsharp-parallel-map-and-reduce-fold-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
