<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Statefulness and the Abstract Universe</title>
	<atom:link href="http://blog.tmorris.net/statefulness-and-the-abstract-universe/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tmorris.net/statefulness-and-the-abstract-universe/</link>
	<description>The weblog of Tony Morris</description>
	<pubDate>Sat, 19 May 2012 03:10:35 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Holgly Morgan</title>
		<link>http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-951</link>
		<dc:creator>Holgly Morgan</dc:creator>
		<pubDate>Fri, 23 Feb 2007 04:09:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-951</guid>
		<description>This is an attempt to say what Tony is saying in a different way.

Basically you don't need mutation to have things that change. A state is a mapping of identifiers to values, that is a state is really just an enviroment.

Env { foo = 2,
        baz = "boo"}

and an enviroment is really just a data structure.

To produce a change in an eviroment we take an old one and produce a new one. So

 // Env now is same as above
foo ++; // the enviroment is being passed to foo implicitly
// foo has returned a new enviroment Env {foo = 3, baz = "boo"}

Since nobody is using the old enviroment it can be garbage collected. Better yet the old enviroment can be recylced. Notice how we are still using mutation but we are not using it directly. This is just like garbage collection vs memory management. In both cases memory is being managed but in the garbage collection case a correct program is being produced faster with less effort, because the computer is taking care of our memory for us.

In general we can represent time varying quantities by using sequences instead of mutation. So instead of using a loop to increment a value we write a pure function which takes the current state and  produces the next state.

for (i=0; i [0, 1,  2, 3, 4, 5, 6........]
take 11 $ iterate foo 0 =&#38;gt; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

I hope that was clear, though I'm not sure it was :)</description>
		<content:encoded><![CDATA[<p>This is an attempt to say what Tony is saying in a different way.</p>
<p>Basically you don&#8217;t need mutation to have things that change. A state is a mapping of identifiers to values, that is a state is really just an enviroment.</p>
<p>Env { foo = 2,<br />
        baz = &#8220;boo&#8221;}</p>
<p>and an enviroment is really just a data structure.</p>
<p>To produce a change in an eviroment we take an old one and produce a new one. So</p>
<p> // Env now is same as above<br />
foo ++; // the enviroment is being passed to foo implicitly<br />
// foo has returned a new enviroment Env {foo = 3, baz = &#8220;boo&#8221;}</p>
<p>Since nobody is using the old enviroment it can be garbage collected. Better yet the old enviroment can be recylced. Notice how we are still using mutation but we are not using it directly. This is just like garbage collection vs memory management. In both cases memory is being managed but in the garbage collection case a correct program is being produced faster with less effort, because the computer is taking care of our memory for us.</p>
<p>In general we can represent time varying quantities by using sequences instead of mutation. So instead of using a loop to increment a value we write a pure function which takes the current state and  produces the next state.</p>
<p>for (i=0; i [0, 1,  2, 3, 4, 5, 6........]<br />
take 11 $ iterate foo 0 =&#38;gt; [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]</p>
<p>I hope that was clear, though I&#8217;m not sure it was <img src='http://blog.tmorris.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Holgly Morgan</title>
		<link>http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-950</link>
		<dc:creator>Holgly Morgan</dc:creator>
		<pubDate>Fri, 23 Feb 2007 03:54:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-950</guid>
		<description>@p: here is an attempt at a short but explanatory explanation. the first thing monads are for is garanteeing that some expressions are evalutated in a certian order.

Do you know what a data dependency is? It's part of compiler implementation practise. Basically when a variable gets it value from somewhere it's said to depend on where it got it from. In other words, in order for a function to use the value it must first evaluate the place it gets its value from first. In theory as long as you evaluate things depended on before you evaluate things that use that thing, your program should produce the same results no matter what order things are evaluated in.

But io doesn't work like this, at least not in mainstream languages. So if change the order of evaluation of statements that do io, you'll produce different results. So how does haskell fix this? By making things that must be evaluated in a certain order have data dependencies between each other. So now haskell can evaluate things in any way it wants, the way functional programming is supposed to work, so long as it respects the data dependencies. How does it acheive this? By making the result of a function use the result of previous functions.

This function is called bind, and in haskell is written &#38;gt;&#38;gt;=. It takes two functions as arguments. The first produces a result and the second takes a result and produces another one. Bind takes these two functions and joins them together.

A not entirely correct analogy, is that in many mainstream languages, arguments must be evaluated before being passed into a function. So if we have that rule and we want certain things to be done in a certain order  we can make a function that does the last thing and pass it the result of doing to the next to last thing as an argument. Since arguments will be evaluated before the function they're being passed to, the next-to-last function call will be evaluated before the last one. So basically bind takes two functions, which it names second (char second(int) {...})  and first (int first () {...}), and rewrites them so we have second(first). Does that kind of make sense?

See my next post for mutation vs functional</description>
		<content:encoded><![CDATA[<p>@p: here is an attempt at a short but explanatory explanation. the first thing monads are for is garanteeing that some expressions are evalutated in a certian order.</p>
<p>Do you know what a data dependency is? It&#8217;s part of compiler implementation practise. Basically when a variable gets it value from somewhere it&#8217;s said to depend on where it got it from. In other words, in order for a function to use the value it must first evaluate the place it gets its value from first. In theory as long as you evaluate things depended on before you evaluate things that use that thing, your program should produce the same results no matter what order things are evaluated in.</p>
<p>But io doesn&#8217;t work like this, at least not in mainstream languages. So if change the order of evaluation of statements that do io, you&#8217;ll produce different results. So how does haskell fix this? By making things that must be evaluated in a certain order have data dependencies between each other. So now haskell can evaluate things in any way it wants, the way functional programming is supposed to work, so long as it respects the data dependencies. How does it acheive this? By making the result of a function use the result of previous functions.</p>
<p>This function is called bind, and in haskell is written &#38;gt;&#38;gt;=. It takes two functions as arguments. The first produces a result and the second takes a result and produces another one. Bind takes these two functions and joins them together.</p>
<p>A not entirely correct analogy, is that in many mainstream languages, arguments must be evaluated before being passed into a function. So if we have that rule and we want certain things to be done in a certain order  we can make a function that does the last thing and pass it the result of doing to the next to last thing as an argument. Since arguments will be evaluated before the function they&#8217;re being passed to, the next-to-last function call will be evaluated before the last one. So basically bind takes two functions, which it names second (char second(int) {&#8230;})  and first (int first () {&#8230;}), and rewrites them so we have second(first). Does that kind of make sense?</p>
<p>See my next post for mutation vs functional</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spoonchops</title>
		<link>http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-949</link>
		<dc:creator>spoonchops</dc:creator>
		<pubDate>Fri, 23 Feb 2007 02:45:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-949</guid>
		<description>My comment got cut off, trying again.

Paul said: “The difference between f(2) and g(fileSystem) is that there is nothing that f can do to “2″ that can cause people to die. There may be things that g can do to “fileSystem” that can cause people to die (whether due to software error or to correctly sending an email that launches a war).”

This is not a valid comment to make.  What's to say that the function f(2) isn't a single line function that erases everything on your hard drive, without seeing the contents of that function you can't know that.  Even if you can see the function's contents and it doesn't seem to be doing that some error in the function could cause it to do that elsewhere.

Secondly when you were comparing abstractions and their "contents" or "real world representations" you've made a huge mistake.  Interacting with the contents of a hard drive is akin to interacting with the contents of the "number two" which has drastic real world consequences.  Think about it, since you were knee high to a grasshopper you've known what 2 means, it's an abstraction with static contents that we as a society all agree on for ease of communication.  If you change the contents of that abstraction (change the "meaning" behind the "number two") even just within the scope of your system, think about the consequences.

This post isn't changing the world as you know it, it's merely looking at it from a different angle and questioning things you (and I) have taken for granted since the infant stage of programming and probably since the beginning of our interaction with a computer of any kind.</description>
		<content:encoded><![CDATA[<p>My comment got cut off, trying again.</p>
<p>Paul said: “The difference between f(2) and g(fileSystem) is that there is nothing that f can do to “2″ that can cause people to die. There may be things that g can do to “fileSystem” that can cause people to die (whether due to software error or to correctly sending an email that launches a war).”</p>
<p>This is not a valid comment to make.  What&#8217;s to say that the function f(2) isn&#8217;t a single line function that erases everything on your hard drive, without seeing the contents of that function you can&#8217;t know that.  Even if you can see the function&#8217;s contents and it doesn&#8217;t seem to be doing that some error in the function could cause it to do that elsewhere.</p>
<p>Secondly when you were comparing abstractions and their &#8220;contents&#8221; or &#8220;real world representations&#8221; you&#8217;ve made a huge mistake.  Interacting with the contents of a hard drive is akin to interacting with the contents of the &#8220;number two&#8221; which has drastic real world consequences.  Think about it, since you were knee high to a grasshopper you&#8217;ve known what 2 means, it&#8217;s an abstraction with static contents that we as a society all agree on for ease of communication.  If you change the contents of that abstraction (change the &#8220;meaning&#8221; behind the &#8220;number two&#8221;) even just within the scope of your system, think about the consequences.</p>
<p>This post isn&#8217;t changing the world as you know it, it&#8217;s merely looking at it from a different angle and questioning things you (and I) have taken for granted since the infant stage of programming and probably since the beginning of our interaction with a computer of any kind.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: spoonchops</title>
		<link>http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-948</link>
		<dc:creator>spoonchops</dc:creator>
		<pubDate>Fri, 23 Feb 2007 01:56:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-948</guid>
		<description>Paul:  "The difference between f(2) and g(fileSystem) is that there is nothing that f can do to “2″ that can cause people to die. There may be things that g can do to “fileSystem” that can cause people to die (whether due to software error or to correctly sending an email that launches a war)."</description>
		<content:encoded><![CDATA[<p>Paul:  &#8220;The difference between f(2) and g(fileSystem) is that there is nothing that f can do to “2″ that can cause people to die. There may be things that g can do to “fileSystem” that can cause people to die (whether due to software error or to correctly sending an email that launches a war).&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul Prescod</title>
		<link>http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-947</link>
		<dc:creator>Paul Prescod</dc:creator>
		<pubDate>Fri, 23 Feb 2007 00:20:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-947</guid>
		<description>I can't make heads nor tails of this post. Of course I can have an abstraction of a network or a hard disk. But interactions with that abstraction have real-world consequences. This necessarily implies that you must treat those abstractions differently than you do the "number 2". That's why Haskell has the IO Monad. On Reddit, you said: "The critical question is, what's the difference between f(2) and g(fileSystem)? Absolutely nothing, that's what." If that was true then there would be no need for the IO Monad. The difference between f(2) and g(fileSystem) is that there is nothing that f can do to "2" that can cause people to die. There may be things that g can do to "fileSystem" that can cause people to die (whether due to software error or to correctly sending an email that launches a war). That's a difference that matters.</description>
		<content:encoded><![CDATA[<p>I can&#8217;t make heads nor tails of this post. Of course I can have an abstraction of a network or a hard disk. But interactions with that abstraction have real-world consequences. This necessarily implies that you must treat those abstractions differently than you do the &#8220;number 2&#8243;. That&#8217;s why Haskell has the IO Monad. On Reddit, you said: &#8220;The critical question is, what&#8217;s the difference between f(2) and g(fileSystem)? Absolutely nothing, that&#8217;s what.&#8221; If that was true then there would be no need for the IO Monad. The difference between f(2) and g(fileSystem) is that there is nothing that f can do to &#8220;2&#8243; that can cause people to die. There may be things that g can do to &#8220;fileSystem&#8221; that can cause people to die (whether due to software error or to correctly sending an email that launches a war). That&#8217;s a difference that matters.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: p</title>
		<link>http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-946</link>
		<dc:creator>p</dc:creator>
		<pubDate>Thu, 22 Feb 2007 15:12:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-946</guid>
		<description>I really want to understand how you can get things done with a purely functional language.  I believe that you can, but someone is going to have to *actually* explain monads before I can make that leap.  I've read several attempts to explain monads of the last few weeks, but they all seem to accidentally assume the reader already knows what they are.

I'm reminded of when I first heard about lambda expressions and closures.  It was this abstract weird bunch of jargon explained by even more jargon and I couldn't make heads or tails of it.  With some digging, I found the right explanation, the one that made me think, "Oh, that's IT?  Why didn't they just SAY so?".

I'm sure there's an article out there about monads that would cut to the chase like that, but I haven't found it yet.</description>
		<content:encoded><![CDATA[<p>I really want to understand how you can get things done with a purely functional language.  I believe that you can, but someone is going to have to *actually* explain monads before I can make that leap.  I&#8217;ve read several attempts to explain monads of the last few weeks, but they all seem to accidentally assume the reader already knows what they are.</p>
<p>I&#8217;m reminded of when I first heard about lambda expressions and closures.  It was this abstract weird bunch of jargon explained by even more jargon and I couldn&#8217;t make heads or tails of it.  With some digging, I found the right explanation, the one that made me think, &#8220;Oh, that&#8217;s IT?  Why didn&#8217;t they just SAY so?&#8221;.</p>
<p>I&#8217;m sure there&#8217;s an article out there about monads that would cut to the chase like that, but I haven&#8217;t found it yet.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cale Gibbard</title>
		<link>http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-945</link>
		<dc:creator>Cale Gibbard</dc:creator>
		<pubDate>Thu, 22 Feb 2007 12:40:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tmorris.net/statefulness-and-the-abstract-universe/#comment-945</guid>
		<description>When you do this, to be honest with your inability to duplicate that resource, you also need to ensure that you don't copy it, or refer to old versions of it. The IO monad also does that, but only by ensuring that you never actually see that resource as a programmer. Uniqueness typing does it more explicitly.</description>
		<content:encoded><![CDATA[<p>When you do this, to be honest with your inability to duplicate that resource, you also need to ensure that you don&#8217;t copy it, or refer to old versions of it. The IO monad also does that, but only by ensuring that you never actually see that resource as a programmer. Uniqueness typing does it more explicitly.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

