<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Comment Feed for Channel 9 - Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad/RSS"></atom:link>
	<image>
		<url>http://ecn.channel9.msdn.com/o9/previewImages/100/443798_100x75.jpg</url>
		<title>Channel 9 - Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<link></link>
	</image>
	<description>Concurrency is a problem that faces all developers as we move to the age of ManyCore processor architectures. Managing state is an important aspect of programming generally and for parallel programming especially. The great&amp;nbsp;Brian
 Beckman demonstrates three ways of labeling a binary tree with unique integer node numbers: (1) by hand, (2) non-monadically, but functionally, by threading an updating counter state variable through function arguments, and (3) monadically, by using a
 partially generalized state-monad implementation to handle the threading via composition. Of course during this lesson from one of the masters of mathematical programming, we wind through various conversational contexts, but always stay true to the default
 topic in a stateful monadic way (watch/listen to this piece to understand what this actually means )This is another great conversation with astrophysicist and programming master Brian Beckman. Brian is one of the true human treasures of Microsoft. If you don&#39;t get mondas, this is a great primer. Even if you don&#39;t care about monadic data types, this is worth
 your time, especially if you write code for a living. This is part 1 of a 2 part series.&amp;nbsp;See Part 2 here.Included with this interview is 
a .zip file containing all of the code and diagrams Brian shows us (including both Haskell and C#). To understand the State Monad program, it may be best to start with Main, seeing how the various facilities are used, then backtrack through the code learning
 first the non-monadic tree labeler, starting with the function Label, then finally the monadic tree labeler, starting with the function MLabel.&amp;nbsp;&amp;nbsp;Below, you will find&amp;nbsp;several exercises for generalizing the constructions further. Brian will monitor this thread so start your coding engines!!Exercise 1: generalize over the type of the state, from int$0 to &amp;lt;S&amp;gt;, say, so that the SM type can handle any kind of$0 state object. Start with Scp&amp;lt;T&amp;gt; --&amp;gt; Scp&amp;lt;S, T&amp;gt;, from &amp;quot;label-content pair&amp;quot; to &amp;quot;state-content pair&amp;quot;.Exercise 2: go from labeling a tree to doing a constrained$0 container computation, as in WPF. Give everything a$0 bounding box, and size subtrees to fit inside their$0 parents, recursively.Exercise 3: promote @return and @bind into an abstract$0 class &amp;quot;M&amp;quot; and make &amp;quot;SM&amp;quot; a subclass of that.Exercise 4 (HARD): go from binary tree to n-ary tree.Exercise 5: Abstract from n-ary tree to IEnumerable; do everything in LINQ! (Hint: SelectMany).Exercise 6: Go look up monadic parser combinators and implement an elegant parser library on top of your new$0 state monad in LINQ.Exercise 7: Verify the Monad laws, either abstractly$0 (pencil and paper), or mechnically, via a program, for the state monad.Exercise 8: Design an interface for the operators @return and @bind and rewrite the state monad so that it implements this interface. See if you can enforce the monad laws (associativity of @bind, left identity of @return, right identity of
 @return) in the interface implementation.Exercise 9: Look up the List Monad and implement it so that it implements the same interface.Exercise 10: deconstruct this entire example by using destructive updates (assignment) in a discipline way that treats the entire CLR and heap memory as an &amp;quot;ambient monad.&amp;quot; Identify the @return and @bind operators in this monad, implement them
 explicitly both as virtual methods and as interface methods. </description>
	<link></link>
	<language>en</language>
	<pubDate>Wed, 22 May 2013 19:21:41 GMT</pubDate>
	<lastBuildDate>Wed, 22 May 2013 19:21:41 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[I was thinking that when Visual Studio 2010 finally ships it would be incredibly useful if all these recent C9 parallelism videos (including related&nbsp;theory ones like Brian's) could be pulled together somehow and bundled with the package. If not actually
 on the DVD then certainly permanently archived online in one, easily navigatable, place.<p>posted by tomkirbygreen</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627560670000000</link>
		<pubDate>Thu, 20 Nov 2008 05:34:27 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627560670000000</guid>
		<dc:creator>tomkirbygreen</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Excellent idea. And it's totally possible by pulling in the content to VS using our tagged RSS feeds. The home page of VS today does exactly this. Putting the content on the DVD is an interesting notion. Not sure how feasible it is given the size constraints
 (all of C9's videos and screencasts related to Parallel Computing would fill up up a DVD or two <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' />
<br /><br />Something that would be really cool would be launching a C9 screencast in VS and having the code in the video automatically written to your VS text editor. So, your text editor extensibly replaces the one in the video stream...<br /><br />C<p>posted by Charles</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627563520000000</link>
		<pubDate>Thu, 20 Nov 2008 05:39:12 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627563520000000</guid>
		<dc:creator>Charles</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[<blockquote><div class="quoteUser">Charles said:</div><div class="quoteText"><br />Something that would be really cool would be launching a C9 screencast in VS and having the code in the video automatically written to your VS text editor. So, your text editor extensibly replaces the one in the video stream...<br /></div></blockquote><br /><br />I think Erik already wrote something like this about a year ago... you should bug him about it<br /><p>posted by Duncanma</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627658370000000</link>
		<pubDate>Thu, 20 Nov 2008 08:17:17 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627658370000000</guid>
		<dc:creator>Duncanma</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p>man, its been a while since briain tied my brain in a knot, ive missed that&nbsp;<img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' />
</p>
<p>posted by aL_</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627678200000000</link>
		<pubDate>Thu, 20 Nov 2008 08:50:20 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627678200000000</guid>
		<dc:creator>aL_</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[still watching but i gotta ask,&nbsp;is the secret stuff brian's working with oslo? or is it something else? <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br /><br /><br />--edit--<br /><br />great stuff :O this interview ranks among the best ones ive seen on channel9 but the wmvhigh version (and possibly the others, havent looked yet) end 1:00:47 real abruptly, is there a part two coming?
<p>posted by aL_</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627701770000000</link>
		<pubDate>Thu, 20 Nov 2008 09:29:37 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627701770000000</guid>
		<dc:creator>aL_</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[My guess would be the deep type system and associated libraries support for notions of mutability and functional purity.&nbsp;David Callahan, Anders et al dropped serious hints about this at the PDC.<p>posted by tomkirbygreen</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627768590000000</link>
		<pubDate>Thu, 20 Nov 2008 11:20:59 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627768590000000</guid>
		<dc:creator>tomkirbygreen</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[I am sorry... but is that&nbsp; a wall of patent cubes on his window sill? O_o<br /><p>posted by AdityaG</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627883440000000</link>
		<pubDate>Thu, 20 Nov 2008 14:32:24 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633627883440000000</guid>
		<dc:creator>AdityaG</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Oh man... Looks like I missed the last part. Dammit. Sometimes my camera creates a second file when interviews last too long... I'll need to find the ending and patch it on and re-upload the files. Thanks for catching this. Sorry for the troubles.<br />C<p>posted by Charles</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628012130000000</link>
		<pubDate>Thu, 20 Nov 2008 18:06:53 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628012130000000</guid>
		<dc:creator>Charles</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Fixed. Broken in two parts now. Sorry about that.... <br /><br /><a target="_blank" href="http://channel9.msdn.com/shows/Going&#43;Deep/Brian-Beckman-The-Zen-of-Stateless-State-The-State-Monad-Part-2/">Part 2</a>.<br /><br />C<p>posted by Charles</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628141200000000</link>
		<pubDate>Thu, 20 Nov 2008 21:42:00 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628141200000000</guid>
		<dc:creator>Charles</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Don't forget to download the samples and start working on the exercises! Brian is lurking....<br /><br /><a target="_blank" href="http://mschnlnine.vo.llnwd.net/d1/ch9/StateMonad.zip"><b>Here are the source files you need for playing with these algorithms in visual studio or your favorite Haskell environment</b></a>.<br /><br />C<p>posted by Charles</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628213760000000</link>
		<pubDate>Thu, 20 Nov 2008 23:42:56 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628213760000000</guid>
		<dc:creator>Charles</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[hey dont worry about it charles, just haappy to be of help <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br />i'll watch part two before doing the excercises, some of them didnt make alot of sense to me even after watching part 1 <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-2.gif' alt='Big Smile' /> (but that might be because of me <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /> )<br /><br />@<a class="shrunk" id="ctl00_MainPlaceHolder_EntryList_ctl07_EntryTemplate_UsernameLink" href="../../../Niners/AdityaG/"><font id="ctl00_MainPlaceHolder_EntryList_ctl07_EntryTemplate_UsernameLabel">AdityaG</font></a><br />sure looks like patent cubes to me :O if you dont stop inventing awsome stuff you'll be walled in brian <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' /><br /><br /><br />(sorry for the spelling, im in belgum and their keyboards are all diffrent)<br /><p>posted by aL_</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628713470000000</link>
		<pubDate>Fri, 21 Nov 2008 13:35:47 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628713470000000</guid>
		<dc:creator>aL_</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p>Best way to attack the exercises is to open up the code samples and go through the C# code line-by-line, letter-by-letter, and compare it to the visio drawings. The transcription (modulo mistakes of course) is supposed to be faithful, one-to-one. The drawings
 are supposed to support the fundamental ideas that will help you crack the exercises. You may want to start each exercise by producing a new drawing from a copy of the old ones that reflects your ideas about how to proceed, then go over and write the code,
 maybe with a little back-and-forth to converge to a refined solution. Always keep copies of &quot;where you started&quot; because you will likely have some false starts.
</p>
<p>Yes, those are cubes, but my collection is tiny compared to Erik Meijer's!</p>
<p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628731890000000</link>
		<pubDate>Fri, 21 Nov 2008 14:06:29 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633628731890000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p>I have a question. I had assumed that the definition of &quot;bad&quot; would be &quot;a function that has side effects&quot;. But Brian gives the key definition as of a mathematical function, which is one that returns the same value given the same arguments. This is much neater
 because it means that you don't have to decide what &quot;side effect&quot; means (could mean a lot of things). But then I realised that this means that a mathematical function CAN have side effects! It just mustn't allow anything to affect what&nbsp;IT returns for a given
 set of arguments - but it is okay for it to affect what other functions will return. Those other functions would not be mathematical, because they reveal the side effects. So a mathematical function doesn't reveal side effects via its return - this says nothing
 about causing them.<br /><br />So my question is, as long as &quot;printf&quot; returns the same value for a given argument, what does it matter if it has the side effect of printing text out to the console? Why can't I add it to my program harmlessly? Previously I was using all mathematical functions,
 now I'm adding a printf call somewhere, that's also a mathematical function, so nothing has changed.<br /><br />(Or can I deduce from this that haskell's equivalent of printf returns a new modified instance of the console every time you call it...? Semi-serious question!)</p>
<p>posted by danielearwicker</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632042620000000</link>
		<pubDate>Tue, 25 Nov 2008 10:04:22 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632042620000000</guid>
		<dc:creator>danielearwicker</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Very astute <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' />&nbsp; So long as the side-effects on other things are absolutely unobservable inside your program, then, yes, you can &quot;get away with&quot; printf'ing to the console. The &quot;however&quot; arises when you want to use the same functions for IO to the console
 that you use for IO to files, where the side effects are absolutely observable in your program, and you want them to be observable. Haskell puts all side-effecting IO functions in the IO monad for conceptual hygiene, even the relatively benign ones that print
 to the console, because you might use the same ones to print to files. You might even want to repurpose your program&nbsp;to printf to a file, as&nbsp;with a pipe command, without rewriting your program,&nbsp;and now you will wish you had been careful <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' />
<br /><br />The IO monad threads around a conceptual &quot;State Of The IO Universe&quot; in just the way the State Monad threads around whatever states you want to play with. Of course, under the covers, the IO Monad implementation keeps track of what's observable and what's not
 observable, keeping up the efficiency. But you get the benefit of just one kind of IO functions, and the usual help of the type system to keep you &quot;mathematical.&quot; The downside is that even to printf to the console for debugging, you must put your program in
 the IO monad at the outset, sigh. <p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632387590000000</link>
		<pubDate>Tue, 25 Nov 2008 19:39:19 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632387590000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[I (think) I solved exercise 1 &amp; 2. These are really ugly in C# - so much nicer in Haskell. Exercise #2 was terrible, until I realized I needed to change my state updating function depending on if I was going &quot;left&quot; or &quot;right.&quot; The single code file is below
 but I have all the code on github:<br /><br />&nbsp; <a href="http://github.com/m4dc4p/statemonad/tree/master">http://github.com/m4dc4p/statemonad/tree/master</a><br /><br /><br />If I continue to work on the exercises, commits will show up there.&nbsp; <br /><br />Exercise1.cs:<br /><br />&nbsp;&nbsp;&nbsp; namespace Exercise1<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Exercise 1: generalize over the type of the state, from int<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // to &lt;S&gt;, say, so that the SM type can handle any kind of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // state object. Start with Scp&lt;T&gt; --&gt; Scp&lt;S, T&gt;, from<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // &quot;label-content pair&quot; to &quot;state-content pair&quot;.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class Scp&lt;State, Contents&gt; // State-Content Pair<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public State label { get; set; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Contents lcpContents { get; set; } // New name; don't confuse<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // with the old &quot;contents&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override string ToString()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return String.Format(&quot;Label: {0}, Contents: {1}&quot;, label, lcpContents);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public delegate Scp&lt;State, Contents&gt; S2Scp&lt;State, Contents&gt;(State state);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public delegate SM&lt;State, Contents2&gt; Maker&lt;State, Contents1, Contents2&gt;(Contents1 input);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class SM&lt;State, Contents&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public S2Scp&lt;State, Contents&gt; s2scp { get; set; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static SM&lt;State, Contents&gt; @return(Contents contents)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new SM&lt;State, Contents&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s2scp = (st =&gt; new Scp&lt;State, Contents&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = st,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcpContents = contents<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static SM&lt;State, Contents2&gt; @bind&lt;Contents2&gt;(SM&lt;State, Contents&gt; inputMonad, Maker&lt;State, Contents, Contents2&gt; inputMaker)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new SM&lt;State, Contents2&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // The new instance of the state monad is a<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // function from state to state-contents pair,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // here realized as a C# lambda expression:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s2scp = (st0 =&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Deconstruct the result of calling the input<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // monad on the state parameter (done by<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // pattern-matching in Haskell, by hand here):<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var lcp1 = inputMonad.s2scp(st0);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var state1 = lcp1.label;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var contents1 = lcp1.lcpContents;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Call the input maker on the contents from<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // above and apply the resulting monad<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // instance on the state from above:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return inputMaker(contents1).s2scp(state1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br /><br />Exercise2.cs:<br /><br />using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Text;<br /><br />namespace StateMonad<br />{<br />&nbsp;&nbsp;&nbsp; namespace Exercise2<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Exercise 2: go from labeling a tree to doing a constrained<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // container computation, as in WPF. Give everything a<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // bounding box, and size subtrees to fit inside their<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // parents, recursively.<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// A container to fit nodes within. Assume nodes fill their<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// container.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class Size<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Size(int w, int h) { Height = h; Width = w; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public int Width { get; private set; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public int Height { get; private set; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override string ToString()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Width.ToString() &#43; &quot;, &quot; &#43; Height.ToString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class Point<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Point(int x, int y) { X = x; Y = y; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public int X { get; private set; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public int Y { get; private set; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override string ToString()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return X.ToString() &#43; &quot;, &quot; &#43; Y.ToString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Given root a tree and a container size, find the rectangles for each<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// node in the tree such that all nodes will fit in the container. Only leafs<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// actually get sizes - branches represent depth only. It is assumed that leaves<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// will fill all available space.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class ConstrainTree<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public delegate Exercise1.SM&lt;Size, Size&gt; Updater();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Exercise1.SM&lt;Size, Size&gt; RightUpdateState()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Exercise1.SM&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s2scp = (size =&gt; new Exercise1.Scp&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = new Size(size.Width * 2, size.Height * 2),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcpContents = size<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Exercise1.SM&lt;Size, Size&gt; LeftUpdateState()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Exercise1.SM&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s2scp = (size =&gt; new Exercise1.Scp&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = new Size(size.Width / 2, size.Height / 2),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcpContents = new Size(size.Width / 2, size.Height / 2)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Exercise1.SM&lt;Size, Program.Tr&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;&gt; Mk&lt;A&gt;(Program.Tr&lt;A&gt; tree, Updater update)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (tree is Program.Lf&lt;A&gt;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var leaf = (Program.Lf&lt;A&gt;)tree;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Exercise1.SM&lt;Size, Size&gt;.bind&lt;Program.Tr&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;&gt;(update(),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (contents1 =&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exercise1.SM&lt;Size, Program.Tr&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;&gt;.@return(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Program.Lf&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contents = new Exercise1.Scp&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = contents1,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcpContents = contents1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var branch = (Program.Br&lt;A&gt;)tree;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var left = branch.left;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var right = branch.right;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Exercise1.SM&lt;Size, Program.Tr&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;&gt;.bind&lt;Program.Tr&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;&gt;(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mk&lt;A&gt;(left, new Updater(LeftUpdateState)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newLeft =&gt; Exercise1.SM&lt;Size, Program.Tr&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;&gt;.bind&lt;Program.Tr&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;&gt;(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mk&lt;A&gt;(right, new Updater(RightUpdateState)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newRight =&gt; Exercise1.SM&lt;Size, Program.Tr&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;&gt;.@return(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Program.Br&lt;Exercise1.Scp&lt;Size, Size&gt;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; left = newLeft,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; right = newRight<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// After traversal the width and height on each node will represent the maximum<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// bounding box size necessary to cover all children of the node, assuming a binary<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// tree laid out &quot;down&quot;. A bounding box of 1 x 1 will over the node itself.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;typeparam name=&quot;Contents1&quot;&gt;&lt;/typeparam&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;param name=&quot;tree&quot;&gt;&lt;/param&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;returns&gt;&lt;/returns&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Program.Tr&lt;Exercise1.Scp&lt;Size, Size&gt;&gt; Bound&lt;A&gt;(Program.Tr&lt;A&gt; tree, Size containerSize)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Mk&lt;A&gt;(tree, new Updater(LeftUpdateState)).s2scp(containerSize).lcpContents;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br /><p>posted by Justin Bailey</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632514790000000</link>
		<pubDate>Tue, 25 Nov 2008 23:11:19 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632514790000000</guid>
		<dc:creator>Justin Bailey</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[I don't quite understand what &quot;state&quot; means and what is being done with it.&nbsp; Passing along state and incrementing it makes sense conceptually, but what mechanism is providing the benefit? The haskell compiler?<br /><br />TIA<br />Ben Lipman<br /><p>posted by benyaboy</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632526490000000</link>
		<pubDate>Tue, 25 Nov 2008 23:30:49 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632526490000000</guid>
		<dc:creator>benyaboy</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<pre class="csharpcode"><font class="rem"><br>// F# Monadic tree labeller (using State Monad from <a href="http://cs.hubfs.net/forums/thread/7472.aspx">http://cs.hubfs.net/forums/thread/7472.aspx</a>)</font>

<font class="kwrd">let</font> <font class="kwrd">rec</font> private mNode (x) =
    <font class="kwrd">match</font> x <font class="kwrd">with</font>
    | Leaf(c) -&gt; state { <font class="kwrd">let</font>! x = GetState
                         <font class="kwrd">do</font>! SetState (x &#43; 1)
                         <font class="kwrd">return</font> Leaf(c,x) }
                         
    | Node(l,r) -&gt; state { <font class="kwrd">let</font>! l = mNode(l)
                           <font class="kwrd">let</font>! r = mNode(r)
                           <font class="kwrd">return</font> Node(l,r) }
                    
<font class="kwrd">let</font> mLabel x = Exec(mNode(x))


<font class="rem">// F# Non-Monadic manual state passing tree labeller</font>

<font class="kwrd">let</font> Label a s = 
    <font class="kwrd">let</font> <font class="kwrd">rec</font> Lab<font class="str">' a s = <br>                match a with <br>                |Leaf(c) -&gt; (Leaf(c,s), s &#43; 1) <br>                <br>                |Node(l,r) -&gt; let l'</font> = Lab<font class="str">' l s <br>                              let r'</font> = Lab<font class="str">' r (snd l'</font>)
                              (Node(fst l<font class="str">', fst r'</font>), (snd r<font class="str">')) <br>     fst (Lab'</font> a s) </pre>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632613090000000</link>
		<pubDate>Wed, 26 Nov 2008 01:55:09 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632613090000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Keep the answers coming! <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /> Great to see!
<div>C</div>
<p>posted by Charles</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632632560000000</link>
		<pubDate>Wed, 26 Nov 2008 02:27:36 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632632560000000</guid>
		<dc:creator>Charles</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<pre class="csharpcode"><font class="rem"><br>//F# State Monad</font>

<font class="kwrd">type</font> State&lt;<font class="str">'state, '</font>a&gt; = State <font class="kwrd">of</font> (<font class="str">'state -&gt;'</font>a * 'state)

<font class="kwrd">type</font> StateMonad() = 
        <font class="kwrd">member</font> b.Bind(m, f) = State (<font class="kwrd">fun</font> s -&gt; <font class="kwrd">let</font> r = <font class="kwrd">match</font> m <font class="kwrd">with</font>
                                                      | State f -&gt; f s
                                              <font class="kwrd">match</font> r <font class="kwrd">with</font>
                                              | (v,s) -&gt; <font class="kwrd">match</font> f v <font class="kwrd">with</font>
                                                         | State f -&gt; f s)    
        <font class="kwrd">member</font> b.Return(x) = State (<font class="kwrd">fun</font> s -&gt; x, s)

<font class="kwrd">let</font> state = StateMonad()

<font class="kwrd">let</font> GetState = State (<font class="kwrd">fun</font> s -&gt; s, s)
<font class="kwrd">let</font> SetState s = State (<font class="kwrd">fun</font> _ -&gt; (), s)  

<font class="kwrd">let</font> Execute m s = <font class="kwrd">match</font> m <font class="kwrd">with</font>
                  | State f -&gt; <font class="kwrd">let</font> r = f s
                               <font class="kwrd">match</font> r <font class="kwrd">with</font>
                               |(x,_) -&gt; x
</pre>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632636530000000</link>
		<pubDate>Wed, 26 Nov 2008 02:34:13 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633632636530000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[&#43;100 <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /> very nice<p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633125690000000</link>
		<pubDate>Wed, 26 Nov 2008 16:09:29 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633125690000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[beautiful!<p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633126080000000</link>
		<pubDate>Wed, 26 Nov 2008 16:10:08 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633126080000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Here is Exercise 3. All the code is available for download at <br /><br /><a href="http://github.com/m4dc4p/statemonad/tree/exercise3">http://github.com/m4dc4p/statemonad/tree/exercise3</a><br /><br />I added some tags so I can push updates and not break the exercises.&nbsp; <br /><br />The M class is abstracted over the contents of the monad, but it feels like it should be abstracted over the specific monad AND the contents. In Haskell the monad class is declared as:<br /><br />&nbsp; class Monad m where<br />&nbsp;&nbsp;&nbsp; (&gt;&gt;=) :: m a -&gt; (a -&gt; m b) -&gt; m b -- bind<br />&nbsp;&nbsp;&nbsp; return :: a -&gt; m a<br /><br />where &quot;m&quot; is abstractd, but I could not get that working in C#. I think that is because C# lacks &quot;higher-kinded&quot; types but I'm not sure. This shows up in my implementation as casts in the overriden bind and @return methods.<br /><br />First my M class:<br /><br />namespace StateMonad<br />{<br />&nbsp;&nbsp;&nbsp; namespace Exercise3<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public abstract class M&lt;Contents1&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public delegate M&lt;Contents2&gt; Maker&lt;Contents2&gt;(Contents1 c);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public abstract M&lt;Contents2&gt; @bind&lt;Contents2&gt;(M&lt;Contents1&gt; input, Maker&lt;Contents2&gt; maker);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public abstract M&lt;Contents1&gt; @return(Contents1 contents);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class Scp&lt;State, Contents&gt; // State-Content Pair<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public State label { get; set; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Contents lcpContents { get; set; } // New name; don't confuse<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // with the old &quot;contents&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override string ToString()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return String.Format(&quot;Label: {0}, Contents: {1}&quot;, label, lcpContents);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public delegate Scp&lt;State, Contents&gt; S2Scp&lt;State, Contents&gt;(State state);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class SM&lt;State, Contents1&gt; : M&lt;Contents1&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public S2Scp&lt;State, Contents1&gt; s2scp { get; set; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override M&lt;Contents2&gt; bind&lt;Contents2&gt;(M&lt;Contents1&gt; input, Maker&lt;Contents2&gt; maker)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // These casts are UGLY but I can't seem to get<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // rid of them ...<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (M&lt;Contents2&gt;) new SM&lt;State, Contents2&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // The new instance of the state monad is a<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // function from state to state-contents pair,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // here realized as a C# lambda expression:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s2scp = (st0 =&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Deconstruct the result of calling the input<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // monad on the state parameter (done by<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // pattern-matching in Haskell, by hand here):<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Scp&lt;State, Contents1&gt; lcp1 = ((SM&lt;State, Contents1&gt;) input).s2scp(st0);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; State state1 = lcp1.label;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Contents1 contents1 = lcp1.lcpContents;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Call the input maker on the contents from<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // above and apply the resulting monad<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // instance on the state from above:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var m = maker(contents1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var r = ((SM&lt;State, Contents2&gt;)m).s2scp(state1);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return r;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override M&lt;Contents1&gt; @return(Contents1 contents)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new SM&lt;State, Contents1&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s2scp = (st =&gt; new Scp&lt;State, Contents1&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = st,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcpContents = contents<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp; }<br />}<br /><br />and the ConstrainedTree example I implemetned in Excercise2 (exactly the same except I added some casts). This is about the most painful C# I've ever had to write!&nbsp; Fortunately teh compiler helps a lot by telling me which types don't match:<br /><br />namespace StateMonad<br />{<br />&nbsp;&nbsp;&nbsp; namespace Exercise3<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class Size<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Size(int w, int h) { Height = h; Width = w; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public int Width { get; private set; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public int Height { get; private set; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public override string ToString()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Width.ToString() &#43; &quot;, &quot; &#43; Height.ToString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class ConstrainTree<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public delegate Exercise3.SM&lt;Size, Size&gt; Updater();<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Exercise3.SM&lt;Size, Size&gt; RightUpdateState()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Exercise3.SM&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s2scp = (size =&gt; new Exercise3.Scp&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = new Size(size.Width * 2, size.Height * 2),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcpContents = size<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Exercise3.SM&lt;Size, Size&gt; LeftUpdateState()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Exercise3.SM&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s2scp = (size =&gt; new Exercise3.Scp&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = new Size(size.Width / 2, size.Height / 2),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcpContents = new Size(size.Width / 2, size.Height / 2)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Exercise3.SM&lt;Size, Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt; Mk&lt;A&gt;(Program.Tr&lt;A&gt; tree, Updater update)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (tree is Program.Lf&lt;A&gt;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var leaf = (Program.Lf&lt;A&gt;)tree;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (Exercise3.SM&lt;Size, Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt;)
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (new Exercise3.SM&lt;Size, Size&gt;()).bind&lt;Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt;(update(),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (contents1 =&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (new Exercise3.SM&lt;Size, Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt;()).@return(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Program.Lf&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contents = new Exercise3.Scp&lt;Size, Size&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; label = contents1,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcpContents = contents1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; })));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var branch = (Program.Br&lt;A&gt;)tree;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var left = branch.left;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var right = branch.right;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (Exercise3.SM&lt;Size, Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (new Exercise3.SM&lt;Size, Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt;()).bind&lt;Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt;(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mk&lt;A&gt;(left, new Updater(LeftUpdateState)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newLeft =&gt; (new Exercise3.SM&lt;Size, Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt;()).bind&lt;Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt;(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Mk&lt;A&gt;(right, new Updater(RightUpdateState)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (newRight =&gt; (new Exercise3.SM&lt;Size, Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;&gt;()).@return(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Program.Br&lt;Exercise3.Scp&lt;Size, Size&gt;&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; left = newLeft,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; right = newRight<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// After traversal the width and height on each node will represent the maximum<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// bounding box size necessary to cover all children of the node, assuming a binary<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// tree laid out &quot;down&quot;. A bounding box of 1 x 1 will over the node itself.<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;typeparam name=&quot;Contents1&quot;&gt;&lt;/typeparam&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;param name=&quot;tree&quot;&gt;&lt;/param&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;returns&gt;&lt;/returns&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static Program.Tr&lt;Exercise3.Scp&lt;Size, Size&gt;&gt; Bound&lt;A&gt;(Program.Tr&lt;A&gt; tree, Size containerSize)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return Mk&lt;A&gt;(tree, new Updater(LeftUpdateState)).s2scp(containerSize).lcpContents;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; }<br />}<br /><br /><br /><p>posted by Justin Bailey</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633346500000000</link>
		<pubDate>Wed, 26 Nov 2008 22:17:30 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633346500000000</guid>
		<dc:creator>Justin Bailey</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Yes, this is a big brain workout, but just think nothing will ever scare you again! The underlying concepts are clean, it just takes a lot of syntax to write them out.
<div><br /></div>
<div>I think you're right about abstracting out by M: no higher-kinded types in C# makes it hard to mimic them. Perhaps it's easier to do this in F#? Not sure, but there is a parallel thread on doing the exercises in F#.</div>
<p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633439380000000</link>
		<pubDate>Thu, 27 Nov 2008 00:52:18 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633439380000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Ben, the State is &quot;anything you like,&quot; and that's the point of some of the exercises: to package, say, layout information in the State. The mechanism doing the threading is the particular pattern of capturing values in closed-over variables (free variables
 inside functions from state to state-value pairs) and then doing the state threading by composition of &quot;functions from state to state-value pairs.&quot; This pattern is so common as to deserve its own library, and, it just so happens that it satisfies the monad
 laws (associativity and right-left unit). So, as they used to say, don't you love it when a plan comes together?&nbsp;
<div><br /></div>
<div>The result is conceptually small code that happens to be completely safe in a parallel, concurrent environment, but can do all kinds of stateful things like laying out visualizables. The code is syntactically a bit big in C#, but I'm really liking the
 way the F# rendition of holoed is looking.</div>
<p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633442480000000</link>
		<pubDate>Thu, 27 Nov 2008 00:57:28 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633442480000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[HINT for Ex 4: look up &quot;mapM&quot; in the Haskell libraries (<a href="http://www.haskell.org">www.haskell.org</a>)<p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633981560000000</link>
		<pubDate>Thu, 27 Nov 2008 15:55:56 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633633981560000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p>I see - so Haskell says &quot;trust me, this won't last&quot; and Haskell is undoubtedly correct!</p>
<p>posted by danielearwicker</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633634077480000000</link>
		<pubDate>Thu, 27 Nov 2008 18:35:48 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633634077480000000</guid>
		<dc:creator>danielearwicker</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<pre class="csharpcode">// F# Monadically label n-ary tree<br></pre>
<pre class="csharpcode">
<font class="kwrd">let</font> MMap f xs = 
            <font class="kwrd">let</font> <font class="kwrd">rec</font> MMap<font class="str">' (f, xs'</font>, out) = 
                state {
                        <font class="kwrd">match</font> xs<font class="str">' with
                        | h :: t -&gt; let! h'</font> = f(h)
                                    <font class="kwrd">return</font>! MMap<font class="str">'(f, t, List.append out [h'</font>])
                        | [] -&gt; <font class="kwrd">return</font> out
                      }
            MMap<font class="str">' (f, xs, [])


let rec private MNNode (x) =
    match x with
    | NLeaf(c) -&gt; state { let! x = GetState
                          do! SetState (x &#43; 1)
                          return NLeaf(c,x) }
                         
    | NNode(xs) -&gt; state { let! xs'</font> = MMap MNNode xs
                           <font class="kwrd">return</font> NNode(xs')  } 
                    
<font class="kwrd">let</font> MNLabel x = Execute(MNNode(x))</pre>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633634300790000000</link>
		<pubDate>Fri, 28 Nov 2008 00:47:59 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633634300790000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<pre class="csharpcode">//LINQ Monadic Labelling of a Binary Tree</pre>
<pre class="csharpcode">
<font class="kwrd">public</font> <font class="kwrd">static</font> StateMonad&lt;BTree&gt; MLabel(BTree tree)
{
    var branch = tree <font class="kwrd">as</font> BBranch;
    var leaf = tree <font class="kwrd">as</font> BLeaf;

    StateMonad&lt;BTree&gt; ret = <font class="kwrd">null</font>;

    <font class="kwrd">if</font> (leaf != <font class="kwrd">null</font>)
    {
        var q = from x <font class="kwrd">in</font> LinqStateMonad.GetState()
                from f <font class="kwrd">in</font> LinqStateMonad.SetState&lt;<font class="kwrd">int</font>&gt;(x &#43; 1)
                select <font class="kwrd">new</font> BLeaf { Content = leaf.Content, State = x };
        ret = s =&gt; { var r = q(s); <font class="kwrd">return</font> <font class="kwrd">new</font> StateContentPair&lt;BTree&gt;(r.Content, r.State); };
    }

    <font class="kwrd">if</font> (branch != <font class="kwrd">null</font>)
    {
        var q = from l <font class="kwrd">in</font> MLabel(branch.Left)
                from r <font class="kwrd">in</font> MLabel(branch.Right)
                select <font class="kwrd">new</font> BBranch() { Left = l, Right = r };
        ret = s =&gt; { var r = q(s); <font class="kwrd">return</font> <font class="kwrd">new</font> StateContentPair&lt;BTree&gt;(r.Content, r.State); };
    }

    <font class="kwrd">return</font> ret;
}</pre>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633636903360000000</link>
		<pubDate>Mon, 01 Dec 2008 01:05:36 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633636903360000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<pre class="csharpcode">//LINQ State Monad implementation</pre>
<pre class="csharpcode"><font class="kwrd">
public</font> <font class="kwrd">delegate</font> StateContentPair&lt;T&gt; StateMonad&lt;T&gt;(<font class="kwrd">int</font> state);<br></pre>
<pre class="csharpcode">
<font class="kwrd">public</font> <font class="kwrd">static</font> <font class="kwrd">class</font> LinqStateMonad
{
    <font class="kwrd">public</font> <font class="kwrd">static</font> StateMonad&lt;U&gt; Select&lt;T, U&gt;(<font class="kwrd">this</font> StateMonad&lt;T&gt; p, Func&lt;T, U&gt; selector)
    {
        <font class="kwrd">return</font> state =&gt; <font class="kwrd">new</font> StateContentPair&lt;U&gt;(selector(p(state).Content), state);
    }
    <font class="kwrd">public</font> <font class="kwrd">static</font> StateMonad&lt;V&gt; SelectMany&lt;T, U, V&gt;(<font class="kwrd">this</font> StateMonad&lt;T&gt; p, Func&lt;T, StateMonad&lt;U&gt;&gt; selector, Func&lt;T, U, V&gt; projector)
    {
        <font class="kwrd">return</font> state =&gt;
        {
            var first = p(state);
            var second = selector(first.Content)(first.State);
            var content = projector(first.Content, second.Content);
            <font class="kwrd">return</font> <font class="kwrd">new</font> StateContentPair&lt;V&gt;(content, second.State);
        };
    }

    <font class="kwrd">public</font> <font class="kwrd">static</font> StateMonad&lt;<font class="kwrd">int</font>&gt; GetState()
    {
        <font class="kwrd">return</font> s =&gt; <font class="kwrd">new</font> StateContentPair&lt;<font class="kwrd">int</font>&gt;(s, s);
    }

    <font class="kwrd">public</font> <font class="kwrd">static</font> StateMonad&lt;T&gt; SetState&lt;T&gt;(<font class="kwrd">int</font> s1)
    {
        <font class="kwrd">return</font> s =&gt; <font class="kwrd">new</font> StateContentPair&lt;T&gt;(<font class="kwrd">default</font>(T), s1);
    }
}</pre>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633636909730000000</link>
		<pubDate>Mon, 01 Dec 2008 01:16:13 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633636909730000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[holoed, this is fantastic! &#43;1000 pts <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633637024640000000</link>
		<pubDate>Mon, 01 Dec 2008 04:27:44 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633637024640000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Brian, I think I get it now.&nbsp; I was thrown off by the example.&nbsp; It makes sense that you need to copy the state around to avoid side affects. &nbsp; I guess the my practical (and procedural) side is too worried that the size of the state and the overhead of
 copying it over and over is too large for the scenarios I deal with.&nbsp; <br /><br />I also agree with what you said in the video about when the project is intricate enough you end up having to deal with all these nasty problems with state dependency, locking, etc.<br /><br />Ben<br /><p>posted by benyaboy</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638621280000000</link>
		<pubDate>Wed, 03 Dec 2008 00:48:48 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638621280000000</guid>
		<dc:creator>benyaboy</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<pre class="csharpcode"><font class="rem">
// F# Parser Monad (<a href="http://www.cs.nott.ac.uk/~gmh/pearl.pdf">http&#58;&#47;&#47;www.cs.nott.ac.uk&#47;&#126;gmh&#47;pearl.pdf</a>)</font>

<font class="kwrd">type</font> Parser&lt;<font class="str">'a&gt; = Parser of (string -&gt;('</font>a * string) list)

<font class="kwrd">let</font> extract(Parser(f)) = f

<font class="kwrd">type</font> ParserMonad() = 
        <font class="kwrd">member</font> b.Bind(p, f) = Parser (<font class="kwrd">fun</font> cs -&gt; 
                                                <font class="kwrd">let</font> r = extract(p) cs
                                                <font class="kwrd">let</font> r<font class="str">' = List.map (fun (a,cs'</font>) -&gt; extract(f a) cs<font class="str">') r
                                                List.concat r'</font>)
        <font class="kwrd">member</font> b.Return(x) = Parser (<font class="kwrd">fun</font> cs -&gt; [x,cs])
        <font class="kwrd">member</font> b.Zero() = Parser (<font class="kwrd">fun</font> cs -&gt; [])


<font class="kwrd">let</font> (&#43;&#43;) p q = Parser(<font class="kwrd">fun</font> cs -&gt; List.append (extract p cs) (extract q cs))
<font class="kwrd">let</font> (&#43;&#43;&#43;) p q = Parser(<font class="kwrd">fun</font> cs -&gt; <font class="kwrd">match</font> (extract(p &#43;&#43; q) cs) <font class="kwrd">with</font>
                                 | [] -&gt; []
                                 | x::xs -&gt; [x])

<font class="kwrd">let</font> parser = ParserMonad()
</pre>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638693140000000</link>
		<pubDate>Wed, 03 Dec 2008 02:48:34 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638693140000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<pre class="csharpcode">
<font class="rem">// F# Parsers combinators :))</font>

<font class="rem">//A parser which successfully consumes the first character</font>
<font class="rem">//if the argument string is non-empty, and fails otherwise.</font>
<font class="kwrd">let</font> item = Parser (<font class="kwrd">fun</font> cs -&gt; <font class="kwrd">match</font> cs <font class="kwrd">with</font>
                             | <font class="str">&quot;&quot;</font> -&gt; []
                             | cs -&gt; [cs.[0], cs.Substring(1)])
                            
<font class="rem">//A combinator sat that takes a predicate, and yields a parser that</font>
<font class="rem">//consumes a single character if it satisfies the predicate, and fails otherwise.</font>
<font class="kwrd">let</font> sat p = parser { <font class="kwrd">let</font>! c = item
                     <font class="kwrd">if</font> p c <font class="kwrd">then</font>
                      <font class="kwrd">return</font> c }
                      
<font class="rem">//A parser for specific characters</font>
<font class="kwrd">let</font> char c = sat (<font class="kwrd">fun</font> s -&gt; c = s)
                                            
<font class="rem">//Parse a specific string</font>
<font class="kwrd">let</font> <font class="kwrd">rec</font> stringp s = <font class="kwrd">match</font> s <font class="kwrd">with</font>
                    | <font class="str">&quot;&quot;</font> -&gt; parser { <font class="kwrd">return</font> [] }
                    | xs -&gt; parser { <font class="kwrd">let</font>! c = char xs.[0]
                                     <font class="kwrd">let</font>! cs = stringp (xs.Substring(1))
                                     <font class="kwrd">return</font> c::cs }                        
                                                          
<font class="rem">//The many combinator permits zero</font>
<font class="rem">//or more applications of p, while many1 permits one or more.</font>
<font class="kwrd">let</font> <font class="kwrd">rec</font> many1 p = parser { <font class="kwrd">let</font>! x = p
                           <font class="kwrd">let</font>! xs = many p
                           <font class="kwrd">return</font> (x::xs) }
<font class="kwrd">and</font> many p = (many1 p) &#43;&#43;&#43; parser { <font class="kwrd">return</font> [] }

                            
<font class="rem">//Parse repeated applications of a parser p, separated by applications of a parser</font>
<font class="rem">//op whose result value is an operator that is assumed to associate to the left,</font>
<font class="rem">//and which is used to combine the results from the p parsers.</font>
<font class="kwrd">and</font> chainl1 p op = 
    <font class="kwrd">let</font> <font class="kwrd">rec</font> rest a = parser { <font class="kwrd">let</font>! f = op
                              <font class="kwrd">let</font>! b = p
                              <font class="kwrd">return</font>! rest (f a b) } &#43;&#43;&#43; parser { <font class="kwrd">return</font> a }
    parser { <font class="kwrd">let</font>! a = p
             <font class="kwrd">return</font>! rest a } 
           
<font class="rem">//Parse a string of spaces.</font>
<font class="kwrd">let</font> space = many (sat (<font class="kwrd">fun</font> s -&gt; Char.IsWhiteSpace s))

<font class="rem">//Parse a token using a parser p, throwing away any trailing space.</font>
<font class="kwrd">let</font> token p = parser { <font class="kwrd">let</font>! a = p
                       <font class="kwrd">let</font>! _ = space
                       <font class="kwrd">return</font> a }

<font class="rem">//Parse a symbolic token:</font>
<font class="kwrd">let</font> symb cs = token (stringp cs)

<font class="rem">//Apply a parser p, throwing away any leading space:</font>
<font class="kwrd">let</font> apply p = extract (parser { <font class="kwrd">let</font>! _ = space
                                <font class="kwrd">let</font>! r = p
                                <font class="kwrd">return</font> r })</pre>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638694770000000</link>
		<pubDate>Wed, 03 Dec 2008 02:51:17 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638694770000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<pre class="csharpcode">
<font class="rem">//F# Monadic Parser - Calculator Example :))) </font>

<font class="rem">// Grammar</font>
<font class="rem">//expr ::= expr addop term j term</font>
<font class="rem">//term ::= term mulop factor j factor</font>
<font class="rem">//factor ::= digit j ( expr )</font>
<font class="rem">//digit ::= 0 j 1 j : : : j 9</font>
<font class="rem">//addop ::= &#43; j -</font>
<font class="rem">//mulop ::= * j /</font>

<font class="kwrd">let</font> addOp = parser { <font class="kwrd">let</font>! _ = symb <font class="str">&quot;&#43;&quot;</font> 
                     <font class="kwrd">return</font> (&#43;) } &#43;&#43;&#43; parser { <font class="kwrd">let</font>! _ = symb <font class="str">&quot;-&quot;</font> 
                                               <font class="kwrd">return</font> (-) } 
<font class="kwrd">let</font> mulOp = parser { <font class="kwrd">let</font>! _ = symb <font class="str">&quot;*&quot;</font> 
                     <font class="kwrd">return</font> (*) } &#43;&#43;&#43; parser { <font class="kwrd">let</font>! _ = symb <font class="str">&quot;/&quot;</font> 
                                               <font class="kwrd">return</font> (/) }  
<font class="kwrd">let</font> digit = parser { <font class="kwrd">let</font>! x = token (sat (<font class="kwrd">fun</font> ch -&gt; Char.IsDigit(ch)))
                     <font class="kwrd">return</font> Char.GetNumericValue(x) - Char.GetNumericValue(<font class="str">'0'</font>) }

<font class="kwrd">let</font> <font class="kwrd">rec</font> expr   = chainl1 term addOp
<font class="kwrd">and</font>     term   = chainl1 factor mulOp
<font class="kwrd">and</font>     factor = digit &#43;&#43;&#43; parser { <font class="kwrd">let</font>! _ = symb <font class="str">&quot;(&quot;</font>
                                    <font class="kwrd">let</font>! n = expr
                                    <font class="kwrd">let</font>! _ = symb <font class="str">&quot;)&quot;</font>
                                    <font class="kwrd">return</font> n }
                                    
<font class="kwrd">let</font> parse s = <font class="kwrd">match</font> apply expr s  <font class="kwrd">with</font>
              | [] -&gt; failwith <font class="str">&quot;failed to parse&quot;</font>
              | (ret, _)::xs -&gt; ret 
                                    </pre>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638696420000000</link>
		<pubDate>Wed, 03 Dec 2008 02:54:02 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638696420000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Nice work (all around)! Thanks for sharing.<br />C<p>posted by Charles</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638756270000000</link>
		<pubDate>Wed, 03 Dec 2008 04:33:47 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633638756270000000</guid>
		<dc:creator>Charles</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[This is true, Ben, but suppose you could think of the entire state of the CLR &amp; heap memory as being the State that gets passed around inside monads of type s -&gt; (s, v)? Could you build up your whole program as &quot;@bind&quot; compositions of things that take
 &quot;the state of the entire CLR&quot; as argument and return pairs of (&quot;state of the entire CLR&quot;, &quot;some values I care about&quot;)? This isn't a rhetorical question, I'm not sure I know how to do it <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' />&nbsp; But it is the question I'm posing to niners in Exercise 10. Of course,
 that &quot;state of the entire CLR&quot; is just a fictional state object, so not heavyweight to &quot;pass around.&quot; It's the ambient monad, I think. But not sure how to guarantee that nothing but the function active at a given moment can modify that state, even if it is
 possible.<br /><br />(btw, in my Caltech days, exams and homework problem sets routinely contained questions the professors didn't know how to answer: open research questions i.o.w.)<p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633640376240000000</link>
		<pubDate>Fri, 05 Dec 2008 01:33:44 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633640376240000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Absolutely heroic!<p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633640376530000000</link>
		<pubDate>Fri, 05 Dec 2008 01:34:13 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633640376530000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Indeed! Hey, holoed. Who are you, man? <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br />C<p>posted by Charles</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633640518820000000</link>
		<pubDate>Fri, 05 Dec 2008 05:31:22 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633640518820000000</guid>
		<dc:creator>Charles</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p class="MsoNormal"></p>
<p class="MsoNormal">Thank you Brian <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></p>
<p class="MsoNormal">I love this stuff. I've been an OO developer for a long time and it is only thank to F# and videos like yours that I started appreciating the beauty of functional ideas. I think my coding at work is improving as a result of this exposure.<br /><br />I plan to have exercise 10 ready before the end of the year <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-5.gif' alt='Wink' />))</p>
<p class="MsoNormal">HoloEd</p>
<p></p>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633641893860000000</link>
		<pubDate>Sat, 06 Dec 2008 19:43:06 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633641893860000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Thank you Charles <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' />
<div><br /></div>
<div>I've updated my profile:</div>
<div><a href="http://channel9.msdn.com/Niners/holoed/">http://channel9.msdn.com/Niners/holoed/</a></div>
<div><br /></div>
<div>Edmondo Pentangelo</div>
<div>Deutsche Bank&nbsp;</div>
<div>London, UK</div>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633641896240000000</link>
		<pubDate>Sat, 06 Dec 2008 19:47:04 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633641896240000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<pre class="csharpcode">
// The List Monad in F#</pre>
<pre class="csharpcode">#light

<font class="kwrd">type</font> List&lt;<font class="str">'a&gt; = List of ('</font>a -&gt; <font class="str">'a list)

type ListMonad() =
    member o.Bind(  (m:'</font>a list), (f: <font class="str">'a -&gt; '</font>b list) ) = List.concat( List.map (<font class="kwrd">fun</font> x -&gt; f x) m )
    <font class="kwrd">member</font> o.Return(x) = [x]

<font class="kwrd">let</font> list = ListMonad()

<font class="kwrd">let</font> cartesian = list { <font class="kwrd">let</font>! x = [1..3]
                       <font class="kwrd">let</font>! y = [4..6]
                       <font class="kwrd">return</font> (x,y) }

printf <font class="str">&quot;%A&quot;</font> cartesian
</pre>
<p>posted by holoed</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633647951160000000</link>
		<pubDate>Sat, 13 Dec 2008 19:58:36 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633647951160000000</guid>
		<dc:creator>holoed</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[woah holoed you Are the man <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-7.gif' alt='Perplexed' /> i havent had time to&nbsp;write out&nbsp;the excercises yet(but ive tried to solve them in my head <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /> ), 8 people (out of 35) are beeling let go from where i work and i have to take over like 2 positions plus my own <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-7.gif' alt='Perplexed' /> nut no more
 excuses <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /> i really really enjoyed this interview&#43;excercises <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br /><br />please pretty please charles and brian,&nbsp; do intervies like this about the other monads as well <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' />
<p>posted by aL_</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633649780910000000</link>
		<pubDate>Mon, 15 Dec 2008 22:48:11 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633649780910000000</guid>
		<dc:creator>aL_</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[Indeed. I bet Brian's excited to dig into the Continuation monad... <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /><br />C<p>posted by Charles</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633649820350000000</link>
		<pubDate>Mon, 15 Dec 2008 23:53:55 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633649820350000000</guid>
		<dc:creator>Charles</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p>&quot;So... any solutions available for the exercises above?&quot; &lt;| Geez! Maybe I should look to see if pages of comments exist before displaying my stupidity to the world. Great work holoed!</p>
<p>posted by Ryan Riley</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633846778530000000</link>
		<pubDate>Fri, 31 Jul 2009 22:57:33 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633846778530000000</guid>
		<dc:creator>Ryan Riley</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p>Here's my solution to exercise 2 using F#:</p>
<p>&nbsp;</p>
<p>The type defs:</p>
<p></p>
<div id="_mcePaste">type Rect =</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp;{ Height: float;</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp;Width: float;</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp;Top: float;</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp;Left: float }</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp;with override r.ToString() = String.Format(&quot;Height: {0}, Width: {1}, Top: {2}, Left: {3}&quot;, r.Height, r.Width, r.Top, r.Left)</div>
<div id="_mcePaste">&nbsp;&nbsp;</div>
<div id="_mcePaste">&nbsp;&nbsp;(* StateBuilder Bounder *)</div>
<div id="_mcePaste">&nbsp;&nbsp;let boundTree tree seed leftUpdater rightUpdater =</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp;let rec labelTree t updater =</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp;match t with</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp;| Leaf(c) &nbsp; &nbsp; &nbsp;-&gt; state { let! s = getState</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;let (next, curr) = updater s</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;do! setState next</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return Leaf(curr, c) }</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp;| Branch(l, r) -&gt; state { let! l = labelTree l leftUpdater</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;let! r = labelTree r rightUpdater</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return Branch(l, r) }</div>
<div id="_mcePaste">&nbsp;&nbsp; &nbsp;exec (labelTree tree leftUpdater) seed</div>
<p>&nbsp;&nbsp;type Rect =</p>
<p>&nbsp;&nbsp; &nbsp;{ Height: float;</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;Width: float;</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;Top: float;</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;Left: float }</p>
<p>&nbsp;&nbsp; &nbsp;with override r.ToString() = String.Format(&quot;Height: {0}, Width: {1}, Top: {2}, Left: {3}&quot;, r.Height, r.Width, r.Top, r.Left)</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;type Tree&lt;'a&gt; =</p>
<p>&nbsp;&nbsp; &nbsp;| Leaf of 'a</p>
<p>&nbsp;&nbsp; &nbsp;| Branch of Tree&lt;'a&gt; * Tree&lt;'a&gt;</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;// The show method already takes into account the tuples,</p>
<p>&nbsp;&nbsp;// unlike the show method that is overloaded in the C# version.</p>
<p>&nbsp;&nbsp;let show tree =</p>
<p>&nbsp;&nbsp; &nbsp;let rec printTree tree level =</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;let spacing = new string(' ', level * indentation)</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;printf &quot;%A&quot; spacing</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;match tree with</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;| Leaf(label, contents) -&gt;</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;let labelString = label.ToString()</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printfn &quot;Leaf: %s, Contents: %A&quot; labelString contents</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;| Branch(left, right) -&gt;</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printfn &quot;Branch: &quot;</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printTree left (level &#43; 1)</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printTree right (level &#43; 1)</p>
<p>&nbsp;&nbsp; &nbsp;printTree tree 0</p>
<p>&nbsp;</p>
The state monad builder:
<p>&nbsp;&nbsp;(* StateMonad *)</p>
<p>&nbsp;&nbsp;type State&lt;'S, 'a&gt; = State of ('S -&gt; 'S * 'a)</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;(* StateBuilder Bounder *)</p>
<p>&nbsp;&nbsp;let boundTree tree seed leftUpdater rightUpdater =</p>
<p>&nbsp;&nbsp; &nbsp;let rec labelTree t updater =</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;match t with</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;| Leaf(c) &nbsp; &nbsp; &nbsp;-&gt; state { let! s = getState</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;let (next, curr) = updater s</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;do! setState next</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return Leaf(curr, c) }</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp;| Branch(l, r) -&gt; state { let! l = labelTree l leftUpdater</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;let! r = labelTree r rightUpdater</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return Branch(l, r) }</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp; &nbsp;exec (labelTree tree leftUpdater) seed</p>
<p></p>
<p>&nbsp;</p>
<p></p>
<p>&nbsp;&nbsp;let eval sm s =</p>
<p>&nbsp;&nbsp; &nbsp;match sm with</p>
<p>&nbsp;&nbsp; &nbsp;| State f -&gt; f s |&gt; fst</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;let exec sm s =</p>
<p>&nbsp;&nbsp; &nbsp;match sm with</p>
<p>&nbsp;&nbsp; &nbsp;| State f -&gt; f s |&gt; snd</p>
<p></p>
<p>&nbsp;</p>
<p>The demo tree:</p>
<p></p>
<p>let demoTree = Branch(</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Leaf(&quot;A&quot;),&nbsp;</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Branch(</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Branch(</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Leaf(&quot;B&quot;),</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Leaf(&quot;C&quot;)),</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Leaf(&quot;D&quot;)))</p>
<p></p>
<p>&nbsp;</p>
<p>The updaters and execution code:</p>
<p></p>
<p>let leftBounder =</p>
<p>&nbsp;&nbsp;fun (depth, rect) -&gt; let newDepth = depth &#43; 1.0</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let multiplier = 2.0 * newDepth</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (newDepth,</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ Height = rect.Height</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Width = rect.Width / multiplier</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Top = rect.Top</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Left = rect.Left &#43; rect.Width / multiplier }),</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { Height = rect.Height</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Width = rect.Width / multiplier</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Top = rect.Top</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Left = rect.Left } )</p>
<p>&nbsp;</p>
<p>let rightBounder =</p>
<p>&nbsp;&nbsp;fun (depth, rect) -&gt; let newDepth = depth - 1.0</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ( (newDepth,</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ Height = rect.Height</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Width = rect.Width * 2.0</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Top = rect.Top</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Left = rect.Left &#43; rect.Width }),</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rect )</p>
<p>&nbsp;</p>
<p>let initialDepth = 0.0</p>
<p>let initialRect = { Height = 100.0</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Width = 100.0</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Top = 0.0</p>
<p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Left = 0.0 } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>let ex2Seed = (initialDepth, initialRect)</p>
<p>&nbsp;</p>
<p>printfn &quot;Bound tree to rects&quot;</p>
<p>let bTree = boundTree demoTree ex2Seed leftBounder rightBounder</p>
<p>show bTree</p>
<p></p>
<p>&nbsp;</p>
<p>This works, but I imagine there must be a better way. I'm open to suggestions.</p>
<p>posted by Ryan Riley</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633866645520000000</link>
		<pubDate>Sun, 23 Aug 2009 22:49:12 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633866645520000000</guid>
		<dc:creator>Ryan Riley</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p>This looks very nice. I don't see any ways right off the top of my head to make it shorter (shorter is almost always better <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif' alt='Smiley' /></p>
<p>posted by brianbec</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633866763040000000</link>
		<pubDate>Mon, 24 Aug 2009 02:05:04 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633866763040000000</guid>
		<dc:creator>brianbec</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p>Thanks for including the visio diagrams. Will print them and look at the code...</p>
<p>posted by exoteric</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633869107770000000</link>
		<pubDate>Wed, 26 Aug 2009 19:12:57 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633869107770000000</guid>
		<dc:creator>exoteric</dc:creator>
	</item>
	<item>
		<title>Re: Brian Beckman: The Zen of Stateless State - The State Monad - Part 1</title>
		<description>
			<![CDATA[
<p>Does the style of logic/flow diagraming (ie. in Visio)&nbsp;have a special name? It seems like a good way to reason about the problem and was hopinh to find out more information about it?</p>
<p>posted by highintensity</p>]]>
		</description>
		<link>http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633988048550000000</link>
		<pubDate>Mon, 11 Jan 2010 11:07:35 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/Shows/Going+Deep/Brian-Beckman-The-Zen-of-Expressing-State-The-State-Monad#c633988048550000000</guid>
		<dc:creator>highintensity</dc:creator>
	</item>
</channel>
</rss>