<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>//TODO: - Chris Marinos' Blog</title>
	
	<link>http://chrismarinos.com</link>
	<description />
	<lastBuildDate>Thu, 06 Oct 2011 20:25:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/marinos" /><feedburner:info uri="marinos" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>C# Async Examples in F# – Part 3</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/U4-h7swiDTs/</link>
		<comments>http://chrismarinos.com/c-async-examples-in-f-part-3/#comments</comments>
		<pubDate>Sat, 01 Oct 2011 23:55:23 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[Async]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://chrismarinos.com/?p=318</guid>
		<description><![CDATA[This post is the third of a series where I am converting the C# 101 Async Samples into F#. See below for the other entries in the series: C# Async Examples in F# &#8211; Part 1 C# Async Examples in F# &#8211; Part 2 The third async example deals with running operations in parallel. The [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post is the third of a series where I am converting the C# <a href="http://www.wischik.com/lu/AsyncSilverlight/AsyncSamples.html">101 Async Samples</a> into F#. See below for the other entries in the series:</em></p>
<p><a href="http://chrismarinos.com/c-async-examples-in-f-part-1/">C# Async Examples in F# &#8211; Part 1</a></p>
<p><a href="http://chrismarinos.com/c-async-examples-in-f-part-2/">C# Async Examples in F# &#8211; Part 2</a></p>
<p> The third async example deals with running operations in parallel. The C# version is structured similarly to the second example, but it starts the string downloads immediately instead of awaiting each result.  </p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
public async void AsyncIntroParallel()
{
    Task&lt;string&gt; page1 = new WebClient().DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov&quot;));
    Task&lt;string&gt; page2 = new WebClient().DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov/climate/&quot;));
    Task&lt;string&gt; page3 = new WebClient().DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov/rss/&quot;));

    WriteLinePageTitle(await page1);
    WriteLinePageTitle(await page2);
    WriteLinePageTitle(await page3);
}
</pre>
</pre>
<p>
For the F# version, I changed things a bit from the last example to use a more functional style:
</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">
member this.AsyncIntroParallel = async {
    let read url = (new WebClient()).AsyncDownloadString(Uri(url))

    let! results = [ &quot;http://www.weather.gov&quot;;
                     &quot;http://www.weather.gov/climate/&quot;;
                     &quot;http://www.weather.gov/rss/&quot; ]
                   |&gt; Seq.map read
                   |&gt; Async.Parallel
    results
    |&gt; Seq.iter this.WriteLinePageTitle
}
</pre>
</pre>
<p>
First, I construct an async workflow for each URL that performs the download. Next, I use the Async.Parallel combinator to tell the operations to start in parallel. Finally, I print the results in order using Seq.iter.
</p>
<p>
I mentioned this in <a href="http://chrismarinos.com/c-async-examples-in-f-part-1/">Part 1</a>, but this example really shows the difference in the way asynchronous operations are started between C# and F#. In C#, tasks are hot, so the three page requests occur immdeidately after the tasks are created. F# requires you to start async blocks by hand, but this gives you some additional flexiblity. Since the call to Async.Parallel at the end of the function is what triggers the parallelism, you can change that call to achieve different behavior while keeping the rest of the code the same. For example, if you want to switch back to synchronous behavior (perhaps for testing), you can do that as follows:</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">
member this.AsyncIntroParallel = async {
    let read url = (new WebClient()).AsyncDownloadString(Uri(url))

    let results = [ &quot;http://www.weather.gov&quot;;
                     &quot;http://www.bing.com&quot;;
                     &quot;http://www.google.com&quot; ]
                  |&gt; Seq.map read
                  |&gt; Seq.map Async.RunSynchronously
    results
    |&gt; Seq.iter this.WriteLinePageTitle
}
</pre>
</pre>
<p>
I prefer the flexibility and composability that the F# approach emphasizes. However, I like that C#&#8217;s hot starting behavior results in slightly less verbose code for simple examples.</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/U4-h7swiDTs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/c-async-examples-in-f-part-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/c-async-examples-in-f-part-3/</feedburner:origLink></item>
		<item>
		<title>C’est la vie</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/jDgp8J7IKAk/</link>
		<comments>http://chrismarinos.com/cest-la-vie/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 08:50:07 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://marinosc.webfactional.com/?p=315</guid>
		<description><![CDATA[As you may have noticed, someone decided it was a good idea to hack my blog. I&#8217;m actually flattered that someone took the time to do it, so thanks for the compliment to whoever did it! Next time I would appreciate a more direct forms of flattery (hint: money). I&#8217;ve re-deployed to a fresh instance [...]]]></description>
			<content:encoded><![CDATA[<p>As you may have noticed, someone decided it was a good idea to hack my blog. I&#8217;m actually flattered that someone took the time to do it, so thanks for the compliment to whoever did it! Next time I would appreciate a more direct forms of flattery (hint: money).</p>
<p>I&#8217;ve re-deployed to a fresh instance of WordPress, but as these things go, it&#8217;s possible that there&#8217;s still a backdoor or other exploit left over from the first attack. I&#8217;ll try to monitor things more closely over the next few days for suspicious activity.</p>
<p>Most site functionality should be working, but feel free to let me know via twitter or some other mechanism if you notice anything funky.</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/jDgp8J7IKAk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/cest-la-vie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/cest-la-vie/</feedburner:origLink></item>
		<item>
		<title>C# Async Examples in F# – Part 2</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/7oy3azweniM/</link>
		<comments>http://chrismarinos.com/c-async-examples-in-f-part-2/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 01:15:09 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[Async]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://chrismarinos.com/?p=306</guid>
		<description><![CDATA[This post is the second of a series where I am converting the C# 101 Async Samples into F#. See below for the other entries in the series: C# Async Examples in F# &#8211; Part 1 C# Async Examples in F# &#8211; Part 3 The second C# Async example deals with making multiple asynchronous web [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post is the second of a series where I am converting the C# <a href="http://www.wischik.com/lu/AsyncSilverlight/AsyncSamples.html">101 Async Samples</a> into F#. See below for the other entries in the series:</em></p>
<p><em><a href="http://chrismarinos.com/c-async-examples-in-f-part-1/">C# Async Examples in F# &#8211; Part 1</a></em></p>
<p><em><a href="http://chrismarinos.com/c-async-examples-in-f-part-3/">C# Async Examples in F# &#8211; Part 3</a></em></p>
<p>The second C# Async example deals with making multiple asynchronous web requests in serial. It’s pretty similar to the first example, but the nature of the example makes a few differences between the C# and F# async models more obvious.</p>
<p>Lets start with the C# sample:</p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
public async void AsyncIntroSerial()
{
    var client = new WebClient();

    WriteLinePageTitle(await client.DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov&quot;)));
    WriteLinePageTitle(await client.DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov/climate/&quot;)));
    WriteLinePageTitle(await client.DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov/rss/&quot;)));
}
</pre>
</pre>
<p>I’ll first show the simplest possible approach to convert it to F#:</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">
let AsyncIntroSerialWithCodeSmell = async {
   let client = new WebClient()

   let! result1 = client.AsyncDownloadString(Uri(&quot;http://www.weather.gov&quot;))
   this.WriteLinePageTitle result1

   let! result2 = client.AsyncDownloadString(Uri(&quot;http://www.weather.gov/climate/&quot;))
   this.WriteLinePageTitle result2

   let! result3 = client.AsyncDownloadString(Uri(&quot;http://www.weather.gov/rss/&quot;))
   this.WriteLinePageTitle result3
}
</pre>
</pre>
<p>This approach is clearly smelly. F# evaluates async expressions using the let! syntax which also binds a name to a value. That means that you need to create a temporary variable to store the result of each async download. This was also true in the first async example, but it’s significantly more ugly here. Fortunately, you can easily rewrite this code to clean things up.</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">
let AsyncIntroSerial = async {
    let client = new WebClient()

    let readAndWrite url = async {
        let! result = client.AsyncDownloadString(Uri(url))
        this.WriteLinePageTitle(result)
    }

    do! readAndWrite &quot;http://www.weather.gov&quot;
    do! readAndWrite &quot;http://www.weather.gov/climate/&quot;
    do! readAndWrite &quot;http://www.weather.gov/rss/&quot;
}
</pre>
</pre>
<p>You can take advantage of F#’s support for nested function definitions and closure to rewrite the code in a DRY manner. I like this refactoring, but I do wish that F#’s computation expression builder syntax allowed me to run an async operation inline like the C# await syntax.</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/7oy3azweniM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/c-async-examples-in-f-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/c-async-examples-in-f-part-2/</feedburner:origLink></item>
		<item>
		<title>C# Async Examples in F# – Part 1</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/7jlW2S_zSpE/</link>
		<comments>http://chrismarinos.com/c-async-examples-in-f-part-1/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 11:00:23 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[Async]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://chrismarinos.com/?p=296</guid>
		<description><![CDATA[This post is the first of a series where I am converting the C# 101 Async Samples into F#. See below for the other entries in the series: C# Async Examples in F# &#8211; Part 2 C# Async Examples in F# &#8211; Part 3 Some of you may be familiar with my boss and C# [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post is the first of a series where I am converting the C# <a href="http://www.wischik.com/lu/AsyncSilverlight/AsyncSamples.html">101 Async Samples</a> into F#. See below for the other entries in the series:</em></p>
<p><em><a href="http://chrismarinos.com/c-async-examples-in-f-part-2/">C# Async Examples in F# &#8211; Part 2</a></em></p>
<p><em><a href="http://chrismarinos.com/c-async-examples-in-f-part-3/">C# Async Examples in F# &#8211; Part 3</a></em></p>
<p>Some of you may be familiar with my boss and C# guru <a href="http://billwagner.cloudapp.net/">Bill Wagner</a>’s series on Async Samples in C#. For those of you who aren’t familiar, he has been working through the <a href="http://www.wischik.com/lu/AsyncSilverlight/AsyncSamples.html">101 Async Samples</a> and posting his comments for each sample. The series is well worth a look if you’re looking to learn about the upcoming async features of C#.</p>
<p>Starting with this post, I’ll also be working through the 101 Async Examples, but I’ll be re-writing them in F#. For each example, I’ll also briefly discuss the tradeoffs between the F# and C# async models. I think that it will be a fun way to compare the C# and F# examples, and I hope to learn a few things along the way. Maybe you will, too! </p>
<p>I’ll try to keep these posts on the short side (no promises), but if you want an in depth comparison of the C# and F# async models, I <em>highly </em>recommend <a href="http://tomasp.net/blog/csharp-fsharp-async-intro.aspx">this excellent series on Asynchronous C# and F#</a> by Tomas Petricek.</p>
<p>With the intro out of the way, let’s take a look at the first sample which makes an asynchronous web request and outputs the result. In C# that looks like this:</p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
public async void AsyncIntroSingle()
{
    WriteLinePageTitle(await new WebClient().DownloadStringTaskAsync(new Uri(&quot;http://www.weather.gov&quot;)));
}
</pre>
</pre>
<p>And now the F# version:</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">
let AsyncIntroSingle() =
    async {
        let client = new WebClient()
        let! result = client.AsyncDownloadString(Uri(&quot;http://www.weather.gov&quot;))
        do WriteLinePageTitle(result)
    }
    |&gt; Async.StartImmediate
</pre>
</pre>
<p>The samples look different on first glance, but the structure is actually fairly similar if you work from the inside out. Both samples start with an extension to WebClient to perform an asynchronous web request. Next, a keyword is used to yield control flow while the async operation occurs. C# uses the await keyword to do this while F# uses let! (more on this later).&#160; Finally, the result is passed to the WriteLinePageTitle function to print the result. </p>
<p>The outermost layer is where things start to differ. The C# version starts the async operation immediately, but the F# requires some extra work. This is one of the major differences between the C# and F# models. C# tasks start as soon as you create them, but F# requires you to manually start the task. For simple examples, this makes the C# version cleaner. However, the F# model gives you more power to compose tasks and decide how they will run.</p>
<p>The last thing that I will point out is F#’s async { } block vs the async keyword on the method signature in C#. These constructs both indicate that asynchronous operations will be performed within a context. In C# this context is a method, but in F# the context is a workflow. This seems like a minor point, but it hints at the significant difference in implementation between C# and F# async. Async in C# is implemented by the compiler, but F# async is not a special language hack. F# <a href="http://msdn.microsoft.com/en-us/library/dd233182.aspx">Computation Expressions</a> (Monads) provide the underpinnings for the F# async model. An explanation of Computation Expressions is well beyond the scope of this post, but know that the same magic that makes the let! keyword perform async operations in this sample can be extended to do other powerful things (like building sequences) in F#.</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/7jlW2S_zSpE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/c-async-examples-in-f-part-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/c-async-examples-in-f-part-1/</feedburner:origLink></item>
		<item>
		<title>Five Reasons the MVP Summit was Awesome</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/gn61IQEF594/</link>
		<comments>http://chrismarinos.com/five-reasons-the-mvp-summit-was-awesome/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 18:58:19 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://chrismarinos.com/?p=279</guid>
		<description><![CDATA[At the start of March, I was fortunate enough to follow up my awesome time at the Java Posse Roundup with an equally awesome time at Microsoft’s MVP Summit. It was my first time at a Summit, so much like the Roundup, I didn’t know what to expect. In the end, it was every bit [...]]]></description>
			<content:encoded><![CDATA[<p>At the start of March, I was fortunate enough to follow up my <a href="http://chrismarinos.com/five-reasons-the-java-posse-roundup-was-awesome-from-a-net-guy/">awesome time at the Java Posse Roundup</a> with an equally awesome time at Microsoft’s <a href="http://mvp.support.microsoft.com/gp/MVPsummit">MVP Summit</a>. It was my first time at a Summit, so much like the Roundup, I didn’t know what to expect. In the end, it was every bit as amazing as I hoped it would be. Here are five reasons why:</p>
<h2>1. Community</h2>
<p>The energy of the MVP community was great. It’s hard to describe the feeling of being surround by hundreds of the most passionate thought leaders in the Microsoft world for three days, but it’s wonderfully refreshing. I really enjoyed the opportunity to pick the brains of experts in technologies that I’m not as familiar with.</p>
<p>While the MVP community as a whole was wonderful, being a part of the F# MVP sub-community was even more rewarding. I spent most of the week hanging out with fellow F#ers <a href="http://richardminerich.com/">Richard Minerich</a>, <a href="http://bloggemdano.blogspot.com/">Daniel Mohl</a>, <a href="http://talbottcrowell.wordpress.com/">Talbott Crowell</a>, <a href="http://nomadic-developer.com/">Aaron Erickson</a>, <a href="http://strangelights.com/blog">Robert Pickering</a>, and <a href="http://www.justinlee.sg">Justin Lee</a>. While I knew many of them from twitter, it was incredibly exciting to meet and exchange ideas in person. We may have had to hand write “F# MVP” on our nametags, but that didn’t stop me from feeling more connected to the F# community than I ever have before. Being around so many passionate F#ers inspired dozens of new ideas for F# projects, and I hope to be able to transform some of those ideas into reality later this year.</p>
<h2>2. “Open Spaces” (The hallway track)</h2>
<p>The summit was definitely not an open spaces conference like the Java Posse Roundup, but the impromptu conversations that took place were just as great. Where else can you see Mads go head to head with Miguel De Icaza on&#160; the future of C#? How about talking C# with Anders and asking him to give F# a little more love in his next keynote (which I may or may not have done). Not to mention all the other direct contact that you have with dozens of product team members. While the topics ranged from TDD to language design to the future of different technologies, all of the hallway discussions were filled with incredibly smart people, and the conversation was rich with great ideas.</p>
<h2>3. NDA Access</h2>
<p>Before I was a MVP, I was frequently annoyed by Summit attendees who tweeted things like, “[REDACTED] is going to be so cool!!!”. I made sure to keep that in the back of my head during my time at the Summit, but it’s undeniably fun to get a sneak peek of the future. Day 2 and 3 of the conference were all about showing us the future and giving product teams feedback on what to improve before things go public. Day 3 was particularly awesome since Don Syme gave the F# MVPs a first hand chance to play around with some of the new F# features. The only downside is that it’s even harder for me to wait for the next release of F#!</p>
<h2>4. Global Reach</h2>
<p>The MVP Community is a global community. At the Summit, I got to know a lot of people from people from places outside of the US like Canada, Singapore, and the UK. Of course, there were also MVPs from all corners of the US in attendance. This wide variety of backgrounds led to a diverse set of opinions and helped me to make a bunch of new friends from around the world. Being part of the worldwide community is a great feeling, but it also meant that I felt a stronger connection to people from the Midwest. I even got to know a few people from my local area that I never got a chance to meet at local events!</p>
<h2>5. Great Accommodations</h2>
<p>Simply put, Microsoft takes care of you while you’re at the Summit. The week was filled with free drinks, free food, and free caffeinated beverages to keep you energized after you were up late at fun evening events. Oh, and they also rented Safeco Field for the attendee party. If a party in a baseball stadium isn’t the perfect way to cap off two weeks of awesome conferences, I don’t know what is!</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/gn61IQEF594" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/five-reasons-the-mvp-summit-was-awesome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/five-reasons-the-mvp-summit-was-awesome/</feedburner:origLink></item>
		<item>
		<title>Five Reasons the Java Posse Roundup was Awesome (from a “.NET guy”)</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/zt8xfHUzUX4/</link>
		<comments>http://chrismarinos.com/five-reasons-the-java-posse-roundup-was-awesome-from-a-net-guy/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 16:33:04 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://chrismarinos.com/five-reasons-the-java-posse-roundup-was-awesome-from-a-net-guy/</guid>
		<description><![CDATA[I recently had the opportunity to attend the Java Posse Roundup, a small open spaces conference put on by the Java Posse and Bruce Eckel. I have mostly focused on the .NET stack professionally, and while I work hard to avoid being a zealot, I still expected to be a .NET outcast in a world [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had the opportunity to attend the <a href="http://www.mindviewinc.com/Conferences/JavaPosseRoundup/">Java Posse Roundup</a>, a small open spaces conference put on by the <a href="http://javaposse.com/">Java Posse</a> and <a href="http://www.bruceeckel.com/">Bruce Eckel</a>. I have mostly focused on the .NET stack professionally, and while I work hard to avoid being a zealot, I still expected to be a .NET outcast in a world of Java developers. Beyond that, I had no idea what to expect from the conference. I had never listened to a Java Posse podcast, and I only went because conference regulars <a href="http://www.yepthatsme.com/">Barry Hawkins</a>, <a href="http://www.srtsolutions.com/author/diannemarsh">Dianne Marsh</a>, and <a href="http://joeracer.blogspot.com/">Joe Nuxoll</a> (a posse member) said that I would enjoy it.</p>
<p>The result? Nothing short of awesome. I had an <em>amazing</em> time. The conference members were very welcoming to a .NET “outsider”, inspiring ideas were exchanged, and I learned a lot about the Java world. Here are five specific reasons why it was worth the trip:</p>
<h2>1. Open Spaces</h2>
<p>If you’ve never experienced open spaces, you need to. In short, open spaces are an effort to facilitate the organic discussions that happen in hallways and around bar tables at normal eyes forward conferences. Attendees post ideas for discussion topics on sticky notes and place them in a time slot, and people get together and talk around that topic. Whoever shows up is the right group, whatever happens, happens, and if you aren’t interested in the topic, it is your responsibility to find (or form) a group that does interest you.</p>
<p>I previously experienced open spaces at <a href="http://codemash.org/">CodeMash</a>, but the Roundup takes it to another level. All of the sessions are open spaces sessions, and <em>all</em> of the attendees really buy into the idea of open spaces, so the conversations that happen are incredible. Another interesting twist at the Roundup is that most of the sessions are recorded which I think helps to make sure people contribute positively to the discussion.</p>
<p>If you still aren’t convinced that the format makes for awesome content, here’s how you know: I was out until at least 2 every night, and I still woke up at 8 every morning to make the 8:30 sessions. There’s no way that I’d make it 5 days at any other conference without skipping at least one morning session.</p>
<h2>2. Lightning Talks</h2>
<p>Two evenings of the conference were devoted to lightning talks, which are presentations lasting 5 minutes or less. There were no limits on topics, and variety was definitely encouraged; topics ranged from taxidermy to Continuous Integration environments and everything in between. The lightning talks educated me about a wide variety of things, but they also helped me learn the attendees interests better which led to even more interesting discussions and stronger connections later in the conference.</p>
<p>Don’t believe me? Check out the <a href="http://www.youtube.com/user/javaposse">lightning talk recordings</a>.</p>
<h2>3. A Small, Welcoming Community</h2>
<p>Unlike most conferences, there were only around 50 attendees at the Roundup, and that was a good thing. Aside from the fact that the town of Crested Butte doesn’t scale well for a much bigger conference, the number of attendees meant that I knew almost everyone there by name by the end of the week. At most larger conferences, you may meet one or two folks that you get to know well, but at the Roundup I was able to develop great connections with dozens of thought leaders in the industry. That type of exposure is invaluable and is much more difficult to encounter at larger conferences.</p>
<h2>4. Cross Training</h2>
<p>As a “.NET guy”, I learned a lot about the culture and thinking of folks in the Java Community. Some folks were even interested in picking my brain about F#. I spent a couple of the afternoons working with <a href="http://dickwallsblog.blogspot.com/">Dick Wall</a> (another posse member) and others working to get the F# Koans running on Ubuntu. Along the way, I was able to learn a lot about Scala by asking Dick to compare the F# features we were working with to Scala. Cross training between platforms and communities like this is incredibly rewarding and educational, and it’s something that I wish we did more of as an industry.</p>
<h2>5. Crested Butte</h2>
<p>A picture’s worth a thousand words:</p>
<p><a href="http://chrismarinos.com/wp-content/uploads/2011/03/IMAG0218.jpg"><img style="background-image: none; border-right-width: 0px; margin: 0px 0px 18px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="IMAG0218" border="0" alt="IMAG0218" src="http://chrismarinos.com/wp-content/uploads/2011/03/IMAG0218_thumb.jpg" width="544" height="328" /></a></p>
<p>Best. Conference Destination. Ever. The one downside? Bonding over skiing, while fun, makes late nights of socializing even more tiring in the morning.</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/zt8xfHUzUX4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/five-reasons-the-java-posse-roundup-was-awesome-from-a-net-guy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/five-reasons-the-java-posse-roundup-was-awesome-from-a-net-guy/</feedburner:origLink></item>
		<item>
		<title>F# on (Ubuntu) Linux with Mono and Monodevelop</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/M8G9SybBIU4/</link>
		<comments>http://chrismarinos.com/f-on-ubuntu-linux-with-mono-and-monodevelop/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 04:54:58 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[mono]]></category>

		<guid isPermaLink="false">http://chrismarinos.com/?p=225</guid>
		<description><![CDATA[This week, I&#8217;m attending the Java Posse Roundup to learn about the interesting things happening on the JVM, meet smart people, and hopefully write some Scala and Clojure code. One of the more surprising emails that I got after registering for the conference came from Dick Wall who asked if I could take an afternoon [...]]]></description>
			<content:encoded><![CDATA[<p>This week, I&#8217;m attending the <a href="http://www.mindviewinc.com/Conferences/JavaPosseRoundup/">Java Posse Roundup</a> to learn about the interesting things happening on the JVM, meet smart people, and hopefully write some Scala and Clojure code. One of the more surprising emails that I got after registering for the conference came from <a href="http://dickwallsblog.blogspot.com/">Dick Wall</a> who asked if I could take an afternoon during the conference to hack some F# with him. Dick prefers to run Ubuntu, and I have wanted to revisit F# on Ubuntu ever since I played around with it a few months back, so I set about installing F# and getting it to run with Monodevelop in Ubuntu.</p>
<p>Below is the process that I used to get everything working <em>on my machine</em>. I don’t claim that this is the best way to do things or that it will even work for anyone else. However, I didn’t find much up to date documentation on the web about running F# on Ubuntu, so hopefully this useful to others. I’ll do my best to keep this up to date, so feel free to post comments on your experiences.</p>
<h2>Background</h2>
<p>Unlike most installs on Ubuntu, mono is tricky. For various reasons, the mono packages in the Ubuntu repositories are significantly out of date, so you will have to build from source to get even semi-recent updates. I decided that I did not want to overwrite the mono installation that ships with Ubuntu, so these instructions will set you up with a <a href="http://www.mono-project.com/Parallel_Mono_Environments">parallel mono installation</a> in /opt/mono.</p>
<h2>Getting Started</h2>
<p>Before you get started, you’ll need to make sure a few prerequisites are installed. You probably already have most of these if you’re a dev.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">sudo apt-get install git build-essential autoconf libtool automake</pre>
</pre>
<p>Next, create (or make sure you have permission to access) /opt/src and /opt/mono since that’s where you&#8217;ll be putting all of the fresh mono bits.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">
cd ~
mkdir src
sudo mv ./src /opt
mkdir mono
sudo mv ./mono /opt
</pre>
</pre>
<h2>Installing mono</h2>
<p>It’s easy to install a parallel mono environment once you know what you’re doing. First, you&#8217;ll need a couple of dependencies.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">sudo apt-get install bison gettext</pre>
</pre>
<p>Next, download the mono source. I chose to install mono 2.10 (which was just released at the time of this writing), but you can install whatever version you&#8217;d like by modifying the git commands below.</p>
<pre>
<pre class="brush: bash; auto-links: false; gutter: false; title: ; notranslate">
cd /opt/src
git clone git://github.com/mono/mono mono
cd mono
git branch mono-2-10 remotes/origin/mono-2-10
git checkout mono-2-10
</pre>
</pre>
<p>Now build and install mono. Note: don’t forget the &#8211;prefix option since that’s how you avoid overwriting the default mono installation.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">
./autogen.sh --prefix=/opt/mono
make
make install
</pre>
</pre>
<h2>Setup a Parallel mono Environment</h2>
<p>Now that your parallel instance of mono is installed in /opt/mono, you need a way to tell your bash environment to use it instead of Ubuntu&#8217;s default mono when you&#8217;re developing. You can do that with a short bash script as described on the parallel mono page.</p>
<p>You can create the script anywhere. I put mine in my home folder</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">vim ~/mono-dev-env</pre>
</pre>
<p>Add the following lines to your script to configure the parallel mono environment.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">
#!/bin/bash
MONO_PREFIX=/opt/mono
GNOME_PREFIX=/usr
export DYLD_LIBRARY_FALLBACK_PATH=$MONO_PREFIX/lib:$DYLD_LIBRARY_FALLBACK_PATH
export LD_LIBRARY_PATH=$MONO_PREFIX/lib:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=$MONO_PREFIX/include:$GNOME_PREFIX/include
export ACLOCAL_PATH=$MONO_PREFIX/share/aclocal
export PKG_CONFIG_PATH=$MONO_PREFIX/lib/pkgconfig:$GNOME_PREFIX/lib/pkgconfig
export PATH=$MONO_PREFIX/bin:$PATH
</pre>
</pre>
<p>Now tell bash to use your new environment.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">source ~/mono-dev-env</pre>
</pre>
<p>You can test that everything is working by running mono -V. Note that if you close your terminal window at any point during the rest of the install, you will have to source the mono-dev-env script again.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">
$ mono -V 

Mono JIT compiler version 2.10 (mono-2-10/1630b8e Thu Feb 10 18:40:28 EST 2011)
Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  x86
    Disabled:      none
    Misc:          softdebug
    LLVM:          supported, not enabled.
    GC:            Included Boehm (with typed GC and Parallel Mark)
</pre>
</pre>
<h2>Install F#</h2>
<p>There are a couple of ways to get F# running under mono, but I chose to also build F# from source. A mono-friendly version of the F# source lives on github. Since you will use F# Interactive, you&#8217;ll also want to grab libgdiplus, which F# Interactive requires to run properly.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">
sudo apt-get install libgdiplus
</pre>
</pre>
<p>With that out of the way, download, build, and install F# from github. Again, don’t forget the &#8211;prefix option. Now is a good time to grab a drink since F# can take a while to build.</p>
<pre>
<pre class="brush: bash; auto-links: false; gutter: false; title: ; notranslate">
cd /opt/src
git clone git://github.com/fsharp/fsharp
cd fsharp
autoreconf
./configure --prefix=/opt/mono
make
make install
</pre>
</pre>
<p>When you’re done, you can run the following to make sure everything went well.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">
fsc
Microsoft (R) F# 2.0 Compiler build (private)
Copyright (c) 2002-2010 Microsoft Corporation. All Rights Reserved.

error FS0207: No inputs specified
</pre>
</pre>
<p>Note that you can also run F# interactive at this point, too.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">
fsi

Microsoft (R) F# 2.0 Interactive build (private)
Copyright (c) 2002-2010 Microsoft Corporation. All Rights Reserved.

For help type #help;;

&gt; exit 0;;
</pre>
</pre>
<p>Right now you already have a full blown F# development environment at your fingertips, so you could stop at this point. I prefer to have monodvelop since I find that having mouse-over type information is very helpful when writing F#.</p>
<h2>Install monodevelop’s Dependencies</h2>
<p>Before you can install monodevelop, you’ll need to grab a few of dependencies, but those dependencies have a few dependencies of their own. Fortunately, you can get all of those from the Ubuntu repositories.</p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">sudo apt-get install libgtk2.0-dev libgconf2-dev libglade2-dev libgnomecanvas2-dev libgnomeui-dev</pre>
</pre>
<p>Now you&#8217;re ready to install gtk-sharp, the first monodevelop dependency. Check out and build the most recent release of gtk-sharp (which at the time of this writing is 2-12).</p>
<pre>
<pre class="brush: bash; auto-links: false; gutter: false; title: ; notranslate">
cd /opt/src
git clone git://github.com/mono/gtk-sharp gtk-sharp
cd gtk-sharp
git branch gtk-sharp-2-12-branch remotes/origin/gtk-sharp-2-12-branch
git checkout gtk-sharp-2-12-branch
./bootstrap-2.12 --prefix=/opt/mono
make
make install
</pre>
</pre>
<p>Next up is mono-addins.</p>
<pre>
<pre class="brush: bash; auto-links: false; gutter: false; title: ; notranslate">
cd /opt/src
git clone git://github.com/mono/mono-addins.git mono-addins
cd mono-addins
./autogen.sh --prefix=/opt/mono
make
make install
</pre>
</pre>
<p>Finally, you’ll also need gnome-sharp.</p>
<pre>
<pre class="brush: bash; auto-links: false; gutter: false; title: ; notranslate">
cd /opt/src
git clone git://github.com/mono/gnome-sharp
cd gnome-sharp
./bootstrap-2.24 --prefix=/opt/mono
make
make install
</pre>
</pre>
<h2>Install monodevelop</h2>
<p>With the dependencies out of the way, you’re clear to install monodevelop. I&#160; got version 2.4 of monodevelop since the F# plugin does not work with the latest builds of monodevelop at the time of writing.</p>
<pre>
<pre class="brush: bash; auto-links: false; gutter: false; title: ; notranslate">
cd /opt/src
git clone git://github.com/mono/monodevelop
cd monodevelop
git branch 2.4 remotes/origin/2.4
git checkout 2.4
./configure --prefix=/opt/mono --profile=core
make
make install
</pre>
</pre>
<h2>Install fsharpbindings</h2>
<p>The fsharpbindings project is a plugin that makes adds support for F# to monodevelop. I had trouble getting the latest source working with a parallel mono 2.10 environment on Ubuntu, but I was able to fix the problems with my own branch of the plugin. I’ve put in a pull request, but for the time being, pull from my fork. I’ll update this post once the main fsharpbindings project works with Ubuntu and mono 2.10.</p>
<pre>
<pre class="brush: bash; auto-links: false; gutter: false; title: ; notranslate">
cd /opt/src
git clone git://github.com/ChrisMarinos/fsharpbinding.git
cd fsharpbinding/
./configure.sh
make
make install
</pre>
</pre>
<h2>One Last Bit of Setup</h2>
<p>You’re almost there. One last bit of setup is required since the current version of fsharpbindings uses different names for the F# compiler and F# Interactive executables. Create symlinks to get the bindings to work. </p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">
cd /opt/mono/bin
ln -s ./fsi ./fsharpi
ln -s ./fsc ./fsharpc
</pre>
</pre>
<h2>Try it Out!</h2>
<p>If everything went according to plan (yeah, right), you should have a full blown F# IDE. Test it out!</p>
<p><em>Note: When testing the install, I received several weird errors the first time I created a F# project in monodevelop. Monodevelop segfaulted once and also complained about not being able to find &#8220;System.Array&#8221;. I&#8217;m not sure why these errors occur, but simply restarting monodevelop fixed them for me. I&#8217;ll update if and when I figure out more.</em></p>
<pre>
<pre class="brush: bash; gutter: false; title: ; notranslate">
cd ~
monodevelop
</pre>
</pre>
<p>You should be able to try out F# by running code in the F# interactive window similar to the one in Visual Studio.</p>
<p>You can also create a console application.</p>
<h2>Summary</h2>
<p>I hope you found the above install process useful, but feel free to leave comments or otherwise contact me if you find problems. F# on mono has come a <em>long</em> way since I last played around with it, and I’m looking forward to watching (and helping) things progress more in the future.</p>
<p>Special thanks to <a href=http://jrwren.wrenfam.com/blog/>Jay Wren</a> for helping me put this together!</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/M8G9SybBIU4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/f-on-ubuntu-linux-with-mono-and-monodevelop/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/f-on-ubuntu-linux-with-mono-and-monodevelop/</feedburner:origLink></item>
		<item>
		<title>C# Expressions vs. F# Quotations: A Syntax Comparison</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/qyxauCCMbgA/</link>
		<comments>http://chrismarinos.com/c-expressions-vs-f-quotations-a-syntax-comparison/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 12:00:00 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://chrismarinos.com/comparing-the-syntax-of-c-expressions-to-f-quotations/</guid>
		<description><![CDATA[In C# the easiest and most common way to create an expression is by implicitly converting a single line lambda into an expression: This implicit conversion is great for some APIs, like the mocking library MOQ: When I use MOQ, I’m glad that the l =&#62; l.Count lambda automatically gets converted to an expression, but [...]]]></description>
			<content:encoded><![CDATA[<p>In C# the easiest and most common way to create an expression is by implicitly converting a single line lambda into an expression:</p>
<pre>
<pre class="brush: csharp; title: ; notranslate">Expression&lt;Func&lt;int, int&gt;&gt; expression = x =&gt; x * 10;
</pre>
</pre>
<p>This implicit conversion is great for some APIs, like the mocking library <a href="http://code.google.com/p/moq/">MOQ</a>:</p>
<pre>
<pre class="brush: csharp; title: ; notranslate">[Test]
public void MoqSample()
{
    var mock = new Mock&lt;IList&lt;int&gt;&gt;();
    mock.SetupGet(l =&gt; l.Count).Returns(15);
    Assert.AreEqual(15, mock.Object.Count);
}
</pre>
</pre>
<p>When I use MOQ, I’m glad that the l =&gt; l.Count lambda automatically gets converted to an expression, but there are pitfalls that you need to be wary of with this conversion.</p>
<p>It’s often good practice to <a href="http://chrismarinos.com/don-t-misuse-lambdas/">refractor complicated lambdas into helper methods</a> for reuse and code clarity:</p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
//Using a simple lambda predicate
var values =
    0.Through(20)
    .Where(x =&gt; x &gt; 15);
</pre>
</pre>
<pre>
<pre class="brush: csharp; title: ; notranslate">
//refactoring the predicate into a helper method
//NOTE: in practice, I'd probably leave this as a lambda
//since it's neither complicated nor multi-purpose.
public bool Condition(int x)
{
    return x &gt; 15;
}

var values =
    0.Through(20)
    .Where(Condition);
</pre>
</pre>
<p>However, you need to be careful when using this technique with some APIs. For example, the following example uses LINQ to SQL to translate a Where predicate into a SQL call:</p>
<pre>
<pre class="brush: csharp; title: ; notranslate">using (var context = new SampleDataContext(&quot;&quot;))
{
    context.Foos.Where(x =&gt; x.Bar == &quot;a match&quot;);
}</pre>
</pre>
<p>If you refactor this predicate into a helper method, the result is not what you may expect:</p>
<pre>
<pre class="brush: csharp; title: ; notranslate">public bool Condition(Foo x)
{
    return x.Bar == &quot;a match&quot;;
}

using (var context = new SampleDataContext(&quot;&quot;))
{
    context.Foos.Where(Condition);
}</pre>
</pre>
<p>The helper method is not implicitly converted into a predicate like the lambda version, but the code still compiles. Instead, the Where method from LINQ to Objects is called. The method will still return the same result, so your integration tests won’t fail, but the behavior has changed. Instead of translating the Where predicate into SQL, the query will pull all of the Foo objects from the database and filter in memory using LINQ to Objects. This can have a huge impact on performance, and only load testing or QA testing this particular part of the application will catch it. Ouch.</p>
<p>The F# version of expressions is quotations, but F# doesn’t implicitly cast lambdas into quotations. Instead, you have to explicitly wrap code using a special notation:</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">let quotation = &lt;@fun x -&gt; x = &quot;a match&quot;@&gt;
</pre>
</pre>
<p>Honestly, I think that this syntax is ugly, but it means that you can’t accidently call the wrong version of an overloaded method like you can in C#. If you translate the LINQ to SQL example from above into F#, it looks like this:</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">//NOTE: The following won't compile since LINQ to SQL
//      doesn't support Where with a quotation
use context = new SampleDataContext(&quot;&quot;)
let values = context.Foos.Where(&lt;@fun x -&gt; x.Bar = &quot;a match&quot;@&gt;)
</pre>
</pre>
<p>Here, the conversion of the predicate into a quotation is explicit. Unfortunately, you can’t have your cake and eat it too, so an F# version of MOQ would also require you to tag your lambdas even when there is no danger of calling the wrong overloaded function:</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">//NOTE: The following won't compile since MOQ doesn't
//      support SetupGet with a quotation
[Test]
let MoqSample() =
    let mock = new Mock&lt;IList&lt;int&gt;&gt;()
    mock.SetupGet(&lt;@fun l -&gt; l.Count@&gt;).Returns(15)
    Assert.AreEqual(15, mock.Object.Count)</pre>
</pre>
<p>Ultimately, choosing between implicit and explicit casting is a game of tradeoffs. Until I encountered the overloading problem with C#’s implicit style, I found F#’s explicit approach to be ugly and unnecessary. Now that I better understand some problems of implicit casting to expressions/quotations, I appreciate the explicit approach- even if I’m still not a big fan of the characters used to make the tags.</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/qyxauCCMbgA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/c-expressions-vs-f-quotations-a-syntax-comparison/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/c-expressions-vs-f-quotations-a-syntax-comparison/</feedburner:origLink></item>
		<item>
		<title>Revisiting Elevate: Seq.pairwise for C#</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/skXm_454LoI/</link>
		<comments>http://chrismarinos.com/revisiting-elevate-seq-pairwise-for-c/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 14:00:00 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Elevate]]></category>
		<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://chrismarinos.com/revisiting-elevate-seq-pairwise-for-c/</guid>
		<description><![CDATA[I’ve been working on a few different projects over the last few months including some work outside of the .NET space. This has been good for my clients, but not so good for Elevate. Fortunately, I found some time the other day to add a new feature: a pairwise implementation for C#. In F#, the [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been working on a few different projects over the last few months including some work outside of the .NET space. This has been good for my clients, but not so good for <a href="http://elevate.codeplex.com">Elevate</a>. Fortunately, I found some time the other day to add a new feature: a pairwise implementation for C#.</p>
<p>In F#, the Seq.pairwise function enables you to walk a sequence two elements at a time. In <a href="http://chrismarinos.com/5-reasons-to-use-f-interactive-in-visual-studio-2010/">F# Interactive</a>, it looks like this:</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">
&gt; [0..3]
  |&gt; Seq.pairwise;;
val it : seq&lt;int * int&gt; = seq [(0, 1); (1, 2); (2, 3)]</pre>
</pre>
<p>It’s an especially useful function to have in your arsenal if you need to compute deltas in a sequence:</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">
&gt; [0;2;5;6;2;5]
  |&gt; Seq.pairwise
  |&gt; Seq.map (fun (l, r) -&gt; r - l)
  |&gt; Seq.toList;;
val it : int list = [2; 3; 1; -4; 3]
</pre>
</pre>
<p>I chose to implement pairwise a little differently in C#. Because C# doesn’t have language support for pattern matching against tuples, I find that they are more clumsy to use than in F#. So, instead of having pairwise return an IEnumerable of Tuples, I created two overloads of pairwise. </p>
<p>One overload accepts a Func to map elements from an IEnumerable:</p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
[Test]
public void PairwiseSelect()
{
    //given a sequence
    var values = 0.Through(5);

    //we can walk the list two elements at a time by using pairwise
    //and find the sum of the two elements
    var result =
        values
        .Pairwise((x, y) =&gt; x+y);

    Assert.That(result, Is.EqualTo(new[] { 1, 3, 5, 7, 9 }));
}
</pre>
</pre>
<p>While the other accepts an action to perform while walking an IEnumerable two elements at a time:</p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
//given a sequence
var values = 0.Through(5);

//we can also use pairwise to execute an action while
//walking a sequence two elements at a time
values.Pairwise((x, y) =&gt; Console.WriteLine(x*y));
</pre>
</pre>
<p>I don&#8217;t use pairwise as frequently as some functions in Elevate/LINQ/Seq, but it’s very useful when you need it. Hopefully I&#8217;ll find more time in the upcoming weeks to contribute more regularly to Elevate!</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/skXm_454LoI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/revisiting-elevate-seq-pairwise-for-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/revisiting-elevate-seq-pairwise-for-c/</feedburner:origLink></item>
		<item>
		<title>5 Reasons to use F# Interactive in Visual Studio 2010</title>
		<link>http://feedproxy.google.com/~r/marinos/~3/DSRgRnpHVEk/</link>
		<comments>http://chrismarinos.com/5-reasons-to-use-f-interactive-in-visual-studio-2010/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 04:42:00 +0000</pubDate>
		<dc:creator>Chris Marinos</dc:creator>
				<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://chrismarinos.com/5-reasons-to-use-f-interactive-in-visual-studio-2010/</guid>
		<description><![CDATA[Note: While the following post is targeted at Visual Studio 2010 users, most of the points apply even if you aren’t using Visual Studio 2010. F# Interactive (FSI) is easy (and free) to install for Visual Studio 2008 users and command line users running in Windows or Mono. Details are available at the F# Developer [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: While the following post is targeted at Visual Studio 2010 users, most of the points apply even if you aren’t using Visual Studio 2010. F# Interactive (FSI) is easy (and free) to install for Visual Studio 2008 users and command line users running in Windows or Mono. Details are available at the <a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx">F# Developer Center</a>.</p>
</blockquote>
<h2>1) You already have it</h2>
<p>F# comes standard with Visual Studio 2010, and it includes F# Interactive. There’s nothing to install, and no configuration is required. You don’t even need to start a F# project in order to use FSI. From anywhere inside Visual Studio, select View | F# Interactive, or just press Ctrl + Alt + F to bring up an FSI instance.</p>
<h2>2) Performance Analysis</h2>
<p>With the #time option enabled, F# Interactive is a surprisingly useful tool for performance analysis. A few days ago, coworkers <a href="http://jrwren.wrenfam.com/blog/">Jay Wren</a> and <a href="http://www.benbarefield.com/">Ben Barefield</a> asked me to help determine why a LINQ statement they wrote was running slowly. After spending time looking over the code and running it through a profiler, we wanted to see how LINQ’s distinct statement behaved with different inputs. Within a couple minutes, I was able to get information using F# Interactive.</p>
<p>First, I wrote a simple setup script:</p>
<pre>
<pre class="brush: fsharp; title: ; notranslate">
open System
open System.Linq

#time

let randomizer = Random()

let sequenceSize = 1000000

let sequential = Enumerable.ToList(Seq.init sequenceSize (fun x -&gt; x.ToString()))
let random = Enumerable.ToList(Seq.init sequenceSize (fun _ -&gt; randomizer.Next(1000)))
</pre>
</pre>
<p>Then I ran couple of statements to test timing: </p>
<pre>
<pre class="brush: plain; title: ; notranslate">
&gt; sequential.Distinct().ToList();;
Real: 00:00:00.336, CPU: 00:00:00.296, GC gen0: 1, gen1: 1, gen2: 1
val it : Collections.Generic.List&lt;string&gt; = seq [&quot;0&quot;; &quot;1&quot;; &quot;2&quot;; &quot;3&quot;; ...]
&gt; random.Distinct().ToList();;
Real: 00:00:00.119, CPU: 00:00:00.031, GC gen0: 0, gen1: 0, gen2: 0
val it : Collections.Generic.List&lt;int&gt; = seq [959; 18; 824; 585; ...]
</pre>
</pre>
<p>F# Interactive is no substitute for more sophisticated performance analysis techniques, but when it comes to getting fast answers to test bottlenecks, it’s a great tool to have at your disposable.</p>
<h2>3) Verifying the Behavior of Base Class Library Functions</h2>
<p>There are a lot of APIs in the Base Class Library, and it can be tough to remember exactly how everything works. Let’s say you can’t remember if the Insert function on List&lt;T&gt; inserts elements before or after the input index. You could write a small console application or a throwaway test to verify the behavior, but it’s a lot faster to use FSI:</p>
<pre>
<pre class="brush: plain; title: ; notranslate">
&gt; open System.Collections.Generic;;
&gt; let list = new List&lt;int&gt;();;

val list : List&lt;int&gt;

&gt; list.Add(0);;
val it : unit = ()
&gt; list.Add(1);;
val it : unit = ()
&gt; list.Add(2);;
val it : unit = ()
&gt; list.Insert(1, 99);;
val it : unit = ()
&gt; list;;
val it : List&lt;int&gt; = seq [0; 99; 1; 2]
&gt;
</pre>
</pre>
<h2>4) Learning F# and Functional Programming</h2>
<p>Learning any language teaches you new coding techniques. Learning a functional language teaches you new problem solving techniques. F# Interactive lets you do both without leaving Visual Studio or closing your open project. Whenever you have a few minutes to kill during development, you can easily open a FSI window and play around with F#. You can also use it to deep dive and explore syntax and techniques with a more extended session. Finally, using F# Interactive while programming in another .NET language is a great way to keep your F# skills sharp even if you aren’t writing F# on a daily basis.</p>
<h2>5) Spikes and Scripting</h2>
<p>This is probably the first use case that people think of when they see FSI (or other REPLs). In practice, I find that I use F# Interactive more for performance analysis, learning F#, and verifying Base Class Library behavior than for spiking or scripting. However, it’s worth pointing out that F# Interactive is a powerful tool for quickly exploring problem domains. By creating script files, you can build up situations to evaluate different approaches without investing a lot of time setting up a dummy project or a clumsy test harness.</p>
<img src="http://feeds.feedburner.com/~r/marinos/~4/DSRgRnpHVEk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://chrismarinos.com/5-reasons-to-use-f-interactive-in-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://chrismarinos.com/5-reasons-to-use-f-interactive-in-visual-studio-2010/</feedburner:origLink></item>
	</channel>
</rss>

