<?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>Jan Varwig &#187; f#</title>
	<atom:link href="http://jan.varwig.org/archive/tag/f/feed" rel="self" type="application/rss+xml" />
	<link>http://jan.varwig.org</link>
	<description>Somewhere between Hello World and HAL9000</description>
	<lastBuildDate>Wed, 17 Mar 2010 11:12:04 +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>Update on F# and Haskell, especially monads</title>
		<link>http://jan.varwig.org/archive/update-on-f-and-haskell-especially-monads</link>
		<comments>http://jan.varwig.org/archive/update-on-f-and-haskell-especially-monads#comments</comments>
		<pubDate>Mon, 08 Oct 2007 08:32:34 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Studium]]></category>
		<category><![CDATA[f#]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[monads]]></category>
		<category><![CDATA[ocaml]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://jan.varwig.org/archiv/update-on-f-and-haskell-especially-monads</guid>
		<description><![CDATA[Since I wrote about F# in August, my progress has been rather slow. There was a lot of work to do for Uni, almost all involving final touches to Pavel, the data-analysis tool me and a few other students have developed as a student research project. We&#8217;ll publish Pavel next week on SourceForge, I&#8217;ll write [...]]]></description>
			<content:encoded><![CDATA[<p>Since I wrote about F# in August, my progress has been rather slow.<br />
There was a lot of work to do for Uni, almost all involving final touches to <a href="http://pavel.sourceforge.net/">Pavel</a>, the data-analysis tool me and a few other students have developed as a student research project. We&#8217;ll publish Pavel next week <a href="http://www.sourceforge.net/projects/pavel/">on SourceForge</a>, I&#8217;ll write a few lines about it then.</p>

<p>Another thing that has held me back is my fascination for Haskell.<span id="more-62"></span> I have read enough of Jason Hickeys <a href="http://www.seas.upenn.edu/~cis500/cis500-f02/resources/ocaml-intro.pdf">Introduktion to the Objective Caml Programming Language</a> to see lots of charming similarities between the two languages, and I&#8217;m really starting to like OCaml/F#, I&#8217;m looking forward to finally writing soemthing useful in it, but Haskell&#8217;s purity and late-binding are still captivating, somehow, making me peek over to the world of Haskell from time to time.</p>

<p>That slumbering interest once gain came back to live when I stumbled upon <a href="http://www.xmonad.org/">XMonad</a> and then, via their press-page, upon Simon Peyton-Jones&#8217; (author of <a href="http://www.haskell.org/ghc/">GHC</a>, a bright, funny guy) OSCON 2007 Presentation <em>A Taste of haskell</em> (<a href="http://blip.tv/file/324976">Part 1</a> and <a href="http://blip.tv/file/325646/">2</a>).<br />
The week after watching the presentation, I was looking for understandable explanations of monads again.
What I&#8217;m always looking out for is a tutorial that treats them not in their entire category-theory-context, and neither in terms of plain haskell. I haven&#8217;t found anything like that so far but several Haskell-based approaches that are written for beginners of Haskell (in contrast to the many written for people with haskell experience) were quite helpful.</p>

<p>The first was <a href="http://www.haskell.org/haskellwiki/Meet_Bob_The_Monadic_Lover">Meet Bob the monadic lover</a>. It starts out lighthearted and funny but the examples get increasingly convoluted and artificial the closer the text comes to the topic of monads.</p>

<p>Next was <a href="http://www.ccs.neu.edu/home/dherman/research/tutorials/monads-for-schemers.txt">A Schemer&#8217;s Introduction to Monads</a> which tries to explain them using CPS. I merely glanced over it since I&#8217;m not a Schemer and I had some tutorials that looked more promising:</p>

<p>In <a href="http://www.linuxjournal.com/article/8850">Everything Your Professor failed to Tell You About Functional Programming</a> Shannon Behrens writes</p>

<blockquote>
  <p>At this point, the reader may be begging for some code. One of the hardest things about learning Haskell is you can&#8217;t understand Haskell without understanding monads, and you can&#8217;t understand most of the monad examples without understanding Haskell.</p>
</blockquote>

<p>(yes!) and gives a glimpse of the monad concept by implementing a monad in Python and Javascript.</p>

<p>Behrens text not being quite enough to fit the concept into my head, <a href="http://moonbase.rydia.net/mental/writings/programming/monads-in-ruby/00introduction.html">MenTaLguY&#8217;s Monads in Ruby Tutorial</a> went a little further by implementing a basic monad using Ruby (which I&#8217;m far more familiar with than Python or JS, whose syntax also doesn&#8217;t get in the way of expressing the essential parts of the monad pattern).<br />
Unfortunately <em>Monads in Ruby</em> was written in 2005 and never quite finished.</p>

<p><a href="http://haskell.org/haskellwiki/Monads_as_containers">Monads as Containers</a> picks up where <em>Monads in Ruby</em> leaves, with in examples in Haskell again. I haven&#8217;t read far enough to actually comment on it though.</p>

<p>A few classics on the topic might come in handy once I&#8217;ve worked through <em>Monads as Containers</em>:
Noel Winstanley&#8217;s <a href="http://www-users.mat.uni.torun.pl/~fly/materialy/fp/haskell-doc/Monads.html">What the hell are monads?</a> and Jeff Newbern&#8217;s <a href="http://www.haskell.org/all_about_monads/html/">All about monads</a>.<br />
I&#8217;m not hardcore enough (yet) to tackle <a href="http://en.wikibooks.org/wiki/Haskell/Category_theory">http://en.wikibooks.org/wiki/Haskell/Category_theory</a> or Eugenia Cheng&#8217;s <a href="http://lambda-the-ultimate.org/node/2455">Tutorial Videos on Monads</a> (blackboard lecture at breakneck speed), both more from a mathematical point of view.</p>

<p>Phew, I was about to write about F# originally.<br />
Although my progress through the tutorial is a little slow, it is very well written and so far I didn&#8217;t encounter any hard parts. Besides that the only noticable thing was a discussion on the F# Mailing list about (automatic) parallelization of F# Code.
Bottom line: automatic generation of parallel code is not possible at the moment due to the unpure nature of OCaml/F#. There exist certain tools however, to help with the manual specification of parallel computations, like the <a href="http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx">Task Parallel Library</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jan.varwig.org/archive/update-on-f-and-haskell-especially-monads/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>F# Observations</title>
		<link>http://jan.varwig.org/archive/f-sharp-observations</link>
		<comments>http://jan.varwig.org/archive/f-sharp-observations#comments</comments>
		<pubDate>Sat, 11 Aug 2007 23:10:59 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[clr]]></category>
		<category><![CDATA[f#]]></category>
		<category><![CDATA[grid-computing]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[monads]]></category>
		<category><![CDATA[ocaml]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://jan.varwig.org/archiv/f-sharp-observations</guid>
		<description><![CDATA[I&#8217;m feeling all mad-scientistic tonight, sipping coke, with 30 tabs open in Opera :) On my journey into the weird world of functional programming on the .NET CLR, I continue to stumble upon interesting stuff. Papers, articles, interviews, each worthy of hours of dedication. Alas, my day still has only 24 hours (I need to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m feeling all mad-scientistic tonight, sipping coke, with 30 tabs open in Opera :)</p>

<p>On my journey into the weird world of functional programming on the .NET CLR, I continue to stumble upon interesting stuff.
Papers, articles, interviews, each worthy of hours of dedication.
Alas, my day still has only 24 hours (I need to work around that somehow), so at the time being I can&#8217;t do much more than glance over everything.<span id="more-57"></span></p>

<p>The questions I was trying to answer during the last few days were (and to a great degree still are):</p>

<ul>
<li>What is the cost of using threads on the CLR and how does F# handle them?</li>
<li>Is F# fast enough to handle computationally-intensive tasks?</li>
<li>Is F# suited for distributed programming?</li>
</ul>

<h3>The cost of using threads on the CLR</h3>

<p>The answer to that question is pretty clear, fortunately. <a href="http://discuss.joelonsoftware.com/default.asp?design.4.435389.16">This thread</a> on the Joel on Software Discussion Board pretty much deals with the question from <a href="/archiv/an-apple-a-day">my last post</a>: <strong>.NET/F# vs. Erlang</strong>.
The initial question in the thread was along the lines of &#8220;I want to do computation with a great bunch (n x 1000) of agents, represented by processes, communicating via messages. Should I use F# or Erlang?&#8221;.</p>

<p>The first answer was already very helpful to me:</p>

<blockquote>
  <p>My understanding is that the .net threads are very heavy weight (128K) when compared to erlang processes (300-400 bytes).</p>
</blockquote>

<p>So, no native CLR threads for larger numbers of processes. After a bit of thinking though, this turns out not to be a problem. What I am planning can easily (perhaps even best) achieved by a few, long-running threads. Yet, the need for many agents and lots of communication might turn up later and I don&#8217;t want to lock myself into something that&#8217;ll leaves me in the lurch later.</p>

<p>Further down the thread, someone posted links to a Microsoft Project called <a href="http://msdn.microsoft.com/msdnmag/issues/06/09/concurrentaffairs/default.aspx">Concurrency and Coordination Runtime</a>, used in the Robotics Studio and fit for precisely this problem.<br />
I have only had a peek into the CCR and if I understand the indroduction of <a href="http://research.microsoft.com/~satnams/">Satnam Singh</a>&#8216;s Paper <a href="https://urresearch.rochester.edu/handle/1802/2105">An Asynchronous Messaging Library for C#</a> correctly, it&#8217;s a library that runs on the unmodified CLR and provides green threads (or something similar) via <a href="http://en.wikipedia.org/wiki/Continuation-passing_style">CPS</a> with good performance.</p>

<p>Im definetly gonna look deeper into this <strike>and I hope there&#8217;s a way to test it out</strike>. Hey cool, it&#8217;s <a href="http://msdn2.microsoft.com/de-de/robotics/bb521232.aspx">free for non-commercial uses</a>!</p>

<h3> Performance of F# and distributed programming</h3>

<p>Its nice <a href="http://www.jroller.com/dmdevito/entry/thoughts_about_java_c_future">performance</a> seems to always be among the major points proponents of OCaml bring up and it was one the major reasons for me to consider F#/OCaml. Hard numbers on F# performance for this weren&#8217;t that easy to find though.
The <a href="http://research.microsoft.com/fsharp/fsharp.aspx">official F# page</a> only claims it to have &#8220;a performance profile like that of C#&#8221;.
<a href="http://dotnet.sys-con.com/read/217534.htm">This article</a> however turned out quite informative:</p>

<blockquote>
  <p>Like OCaml, F# is excellent at writing tools for symbolic programming. Examples of this type of programming include static analysis, compilers, and other <strong>sophisticated analyses over structured data terms</strong>. Remember using Maple or Matlab? How about Mathematica? That&#8217;s what writing F# is like. If F# is to be used to analyze various complex problems, then harnessing it to a virtual supercomputer seemed like a logical thing. Slated to learn two new technologies, I was hoping I hadn&#8217;t bit off more than I could chew.</p>
</blockquote>

<p>(emphasis mine)</p>

<p>This is exactly my situation. The article describes an experiment in distributing a computationally intensive algorithm over multiple machines using <a href="http://www.sourceforge.net/projects/alchemi">Alchemi</a>, a .NET Grid Computing Framework which was deployed first using pure C#, then F# wrapped in C# and finally pure F#. The results?</p>

<blockquote>
  <p>Without any optimization the F# implementation took 453 ms. C# finished up in 62 ms. Turning optimization on caused the C# results to drop to 46 ms. And, most shocking of all, the F# was dead even at 46 ms! Apparently, the F# compiler does an excellent job optimizing the code. Continuing on, I ran the entire C# and F# grid applications against one another. Without any optimization the C# code took 3.9 seconds to calculate 100 digits of pi while F# only took 2.8 seconds. Optimizing this application showed that F# would finish in 1.5 seconds while C# would not complete any faster than 2.6 seconds.</p>
</blockquote>

<p>Nice!</p>

<h3>Next steps</h3>

<p>I&#8217;m definetly gonne work my way through one of the excellent OCaml tutorials online.<br />
The ones that seem recommended most often are</p>

<ul>
<li><a href="http://pauillac.inria.fr/~remy/cours/appsem/ocaml.pdf">Using, Understanding, and Unraveling the OCaml Language</a> by Didier Rémy</li>
<li><a href="http://www.cs.caltech.edu/courses/cs134/cs134b/book.pdf">Introduction to the Objective Caml Programming Language</a> by <a href="http://www.cs.caltech.edu/~jyh/">Jason Hickey</a></li>
<li><a href="http://caml.inria.fr/pub/docs/oreilly-book/">Developing Applications With Objective Caml</a>, an entire book, available online with whopping 750 pages</li>
</ul>

<h3>More Stuff</h3>

<p>Like always, browsing the web got me sidetracked here and there instead of keeping me focused on F#.<br />
I want to share the most interesting discoveries with you.</p>

<ul>
<li><a href="http://www.albahari.com/threading/">Threading in C#</a> by Joseph Albahari is a pretty profound free online book about, well, threading in C#</li>
<li><a href="http://channel9.msdn.com/Showpost.aspx?postid=230438">Brian Beckman: Monads, Monoids, and Mort</a> is a Channel 9  interview in which Brian tells a bit of history about his career, chats about functional programming, nicely explains Monoids and Monads on the way and introduces a pretty shocking statement about the relation between VisualBasic and C# at Microsoft Research.</li>
<li><a href="http://fsharpnews.blogspot.com/">F# News</a> is a blog that deals solely with, who&#8217;d have guessed it, F#</li>
<li><a href="http://www.ffconsultancy.com/products/fsharp_for_visualization/index.html">F# for Visualization</a> is a book from Flying Frog. The page links to an impressive Demo illustrating F#&#8217;s performance.</li>
<li><a href="http://www.haskell.org/haskellwiki/Meet_Bob_The_Monadic_Lover">Meet Bob the Monadic Lover</a> seems to be a very entertaining introduction to monads. I haven&#8217;t read it yet though, I&#8217;m still fighting my way through&#8230;</li>
<li><a href="http://www.cs.toronto.edu/~sme/presentations/cat101.pdf">Category Theory for Beginners</a>, great slides from an introductory course into category theory which focus on the motivations behind and practical uses of category theory for computer scientists.</li>
</ul>

<p>Holy crap, that was a long post.</p>
]]></content:encoded>
			<wfw:commentRss>http://jan.varwig.org/archive/f-sharp-observations/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Hey Hey OCaml</title>
		<link>http://jan.varwig.org/archive/hey-hey-ocaml</link>
		<comments>http://jan.varwig.org/archive/hey-hey-ocaml#comments</comments>
		<pubDate>Tue, 07 Aug 2007 20:33:51 +0000</pubDate>
		<dc:creator>Jan</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[f#]]></category>
		<category><![CDATA[ocaml]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[steve-yegge]]></category>

		<guid isPermaLink="false">http://jan.varwig.org/archiv/hey-hey-ocaml</guid>
		<description><![CDATA[Wie&#8217;s aussieht hat sich auch Steve Yegge schon damit beschäftigt: OCaml has threads, exceptions, call-with-continuation, calling conventions to and from C, a rich standard library with collections, networking, I/O, graphics, a complete interface to the Unix programming API, and a powerful module system that blows Java&#8217;s packages away. It has interfaces and bindings for Oracle, [...]]]></description>
			<content:encoded><![CDATA[<p>Wie&#8217;s aussieht hat sich auch <a href="http://steve-yegge.blogspot.com/">Steve Yegge</a> schon <a href="http://steve.yegge.googlepages.com/ocaml">damit</a> <a href="http://steve.yegge.googlepages.com/more-ocaml">beschäftigt</a>:</p>

<blockquote>
  <p>OCaml has threads, exceptions, call-with-continuation, calling conventions to and from C, a rich standard library with collections, networking, I/O, graphics, a complete interface to the Unix programming API, and a powerful module system that blows Java&#8217;s packages away. It has interfaces and bindings for Oracle, MySQL, postgres, berkeley DBs, CORBA, COM, xml-rpc, SOAP, XML, perl-compatible regular expressions&#8230; the list goes on. You name it, it&#8217;s there.</p>
  
  <p>OCaml has the potential to make me happy as a programmer, finally.</p>
</blockquote>

<p>Mjamm :)<span id="more-56"></span>
<blockquote>
  <p>At first I was a bit amazed at how much support there is for real-world development in OCaml &#8211; as far as I can tell, it&#8217;s got everything you&#8217;d find in any other mainstream language, with a relatively smaller user community.</p>
  
  <p>But now I think it&#8217;s not amazing at all; it&#8217;s a natural consequence of the fact that it&#8217;s simply a superior language. It stands to reason that if you have a language that really does live up to the promise of making people (say) 10 times as productive as the other languages out there, then it will only take 1/10th the people (or time) to reproduce the functionality that&#8217;s been created for other languages. And it&#8217;s been around for a decade &#8211; much longer if you consider that it was derived from ML, which started in the late 1980s.</p>
</blockquote></p>

<p>Ich denke ich werde da mal nen Blick riskieren. Auch wenn Steve anmerkt, dass OCaml für Webserver ungeeignet sei (leider ohne zu erklären warum).
Für Server gibt es jede Menge mächtige Sprachen, vielleicht ist Erlang da das richtige (wenn nicht, da ist immernoch Ruby), aber eine mächtige Sprache für den Desktop&#8230;
das klingt zu verlockend, <em>gerade</em> mit der .NET Anbindung von F#.</p>

<p>Ich werde mir mal <a href="http://www.ocaml-tutorial.org/">die hier</a> zu Gemüte führen.</p>
]]></content:encoded>
			<wfw:commentRss>http://jan.varwig.org/archive/hey-hey-ocaml/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
