<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Functional D: Is Transitive Const Fundamental?</title>
	<atom:link href="http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/</link>
	<description>Hans-Eric Grönlund on software development</description>
	<lastBuildDate>Wed, 21 Dec 2011 04:18:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>By: Lorencorah</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-51633</link>
		<dc:creator>Lorencorah</dc:creator>
		<pubDate>Sat, 11 Dec 2010 17:03:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-51633</guid>
		<description>Is it possible to contact administration? 
Hih you hear me??</description>
		<content:encoded><![CDATA[<p>Is it possible to contact administration?<br />
Hih you hear me??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans-Eric</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-13292</link>
		<dc:creator>Hans-Eric</dc:creator>
		<pubDate>Thu, 31 Jul 2008 14:34:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-13292</guid>
		<description>I am bound to agree with you, now that I finally understood :-)</description>
		<content:encoded><![CDATA[<p>I am bound to agree with you, now that I finally understood <img src='http://www.hans-eric.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mort</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-13288</link>
		<dc:creator>mort</dc:creator>
		<pubDate>Thu, 31 Jul 2008 13:22:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-13288</guid>
		<description>I think it&#039;s actually pretty intuitive if you define pure to mean &#039;a function completely determined by the value of its parameters&#039;, and think of the parameters as defining deep values.  Then if those values are being mutated concurrently, it makes sense that you lose determinism.

Actually I think the current proposal for &#039;pure&#039; is pretty broken for the reasons mentioned above:  pure functions aren&#039;t usable on mutable values and mutable functions can&#039;t be used on the local mutable values inside pure code.  That thread I linked to is many months old - I wonder if they&#039;ve addressed this...</description>
		<content:encoded><![CDATA[<p>I think it&#8217;s actually pretty intuitive if you define pure to mean &#8216;a function completely determined by the value of its parameters&#8217;, and think of the parameters as defining deep values.  Then if those values are being mutated concurrently, it makes sense that you lose determinism.</p>
<p>Actually I think the current proposal for &#8216;pure&#8217; is pretty broken for the reasons mentioned above:  pure functions aren&#8217;t usable on mutable values and mutable functions can&#8217;t be used on the local mutable values inside pure code.  That thread I linked to is many months old &#8211; I wonder if they&#8217;ve addressed this&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans-Eric</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-13274</link>
		<dc:creator>Hans-Eric</dc:creator>
		<pubDate>Thu, 31 Jul 2008 10:19:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-13274</guid>
		<description>Now I (finally) see where you&#039;re driving at. You want to allow for what Bruno Madeiros (in the news thread you provided) call &quot;partially pure&quot; functions along with pure (the compiler would have to figure out which is which, which is trivial).
Interesting concept. 
The only disadvantage I can think of, and it&#039;s a minor one, is that programmers might think they&#039;re writing thread-safe code when they&#039;re not. Partially pure functions are only thread-safe when invoked from within a truly pure function; at top-level on the other hand, they&#039;re not.</description>
		<content:encoded><![CDATA[<p>Now I (finally) see where you&#8217;re driving at. You want to allow for what Bruno Madeiros (in the news thread you provided) call &#8220;partially pure&#8221; functions along with pure (the compiler would have to figure out which is which, which is trivial).<br />
Interesting concept.<br />
The only disadvantage I can think of, and it&#8217;s a minor one, is that programmers might think they&#8217;re writing thread-safe code when they&#8217;re not. Partially pure functions are only thread-safe when invoked from within a truly pure function; at top-level on the other hand, they&#8217;re not.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mort</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-13270</link>
		<dc:creator>mort</dc:creator>
		<pubDate>Thu, 31 Jul 2008 09:05:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-13270</guid>
		<description>If a pure function&#039;s parameters are marked as const, then they can change.  Agreed, that&#039;s the point - it allows you to operate on mutable data.  If you want to require invariance of the data, you use &#039;invariant&#039; to specify that.  Trying to come up with a scheme for specifying things as &#039;temporarily immutable&#039; looks like a can of worms to me.

The other benefit of allowing pure non-invariant functions is that you can write pure helper functions that do mutate their arguments.  With only pure invariant functions, if you do local mutations on the stack in a pure (invariant) function, there is no way to factor those mutations out into functions.  So you may find yourself cutting/pasting code.  That seems like a pretty bad situation.</description>
		<content:encoded><![CDATA[<p>If a pure function&#8217;s parameters are marked as const, then they can change.  Agreed, that&#8217;s the point &#8211; it allows you to operate on mutable data.  If you want to require invariance of the data, you use &#8216;invariant&#8217; to specify that.  Trying to come up with a scheme for specifying things as &#8216;temporarily immutable&#8217; looks like a can of worms to me.</p>
<p>The other benefit of allowing pure non-invariant functions is that you can write pure helper functions that do mutate their arguments.  With only pure invariant functions, if you do local mutations on the stack in a pure (invariant) function, there is no way to factor those mutations out into functions.  So you may find yourself cutting/pasting code.  That seems like a pretty bad situation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans-Eric</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-13265</link>
		<dc:creator>Hans-Eric</dc:creator>
		<pubDate>Thu, 31 Jul 2008 08:23:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-13265</guid>
		<description>If the parameters are marked as invariant, mutability can not leak, but - and that was my point - if they are merely marked as const there is a possibility that someone else changes the data while the pure function is executing (in a different thread). Thus, pureness requires invariant arguments.
You have a (contrived) code example that highlights this in my first reply.
</description>
		<content:encoded><![CDATA[<p>If the parameters are marked as invariant, mutability can not leak, but &#8211; and that was my point &#8211; if they are merely marked as const there is a possibility that someone else changes the data while the pure function is executing (in a different thread). Thus, pureness requires invariant arguments.<br />
You have a (contrived) code example that highlights this in my first reply.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mort</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-13223</link>
		<dc:creator>mort</dc:creator>
		<pubDate>Wed, 30 Jul 2008 21:50:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-13223</guid>
		<description>Ok, I just found a thread on the D forums discussing this very idea.  You can find it here:  http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&amp;article_id=70762

I didn&#039;t see any compelling arguments against it in skimming the thread.  One thing I think you&#039;d need is to generalize the rules if you wanted to allow nested pure functions: I think they shouldn&#039;t be able to access any non-invariant data from their environment (including globals and variables in scope).</description>
		<content:encoded><![CDATA[<p>Ok, I just found a thread on the D forums discussing this very idea.  You can find it here:  <a href="http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&#038;article_id=70762" rel="nofollow">http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&#038;article_id=70762</a></p>
<p>I didn&#8217;t see any compelling arguments against it in skimming the thread.  One thing I think you&#8217;d need is to generalize the rules if you wanted to allow nested pure functions: I think they shouldn&#8217;t be able to access any non-invariant data from their environment (including globals and variables in scope).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mort</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-13221</link>
		<dc:creator>mort</dc:creator>
		<pubDate>Wed, 30 Jul 2008 21:36:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-13221</guid>
		<description>If you have a function marked pure (in my sense) whose parameters are also marked invariant (or even just const), how can mutability leak in?   Obviously you can create *local* mutable state (on the stack), but according to Andrei Alexandrescu’s slides, you&#039;ll be able to do that even if a function is marked pure in your sense.  But I don&#039;t see how you can get past the parameters being invariant to do anything undesirable.  Can you give a code example?</description>
		<content:encoded><![CDATA[<p>If you have a function marked pure (in my sense) whose parameters are also marked invariant (or even just const), how can mutability leak in?   Obviously you can create *local* mutable state (on the stack), but according to Andrei Alexandrescu’s slides, you&#8217;ll be able to do that even if a function is marked pure in your sense.  But I don&#8217;t see how you can get past the parameters being invariant to do anything undesirable.  Can you give a code example?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans-Eric</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-13218</link>
		<dc:creator>Hans-Eric</dc:creator>
		<pubDate>Wed, 30 Jul 2008 21:01:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-13218</guid>
		<description>Ok, I didn&#039;t get that (I&#039;m a bit slow at times :-) ). But if one does what you suggests (pure keyword that only forbids global state access and calls to non-pure functions) there is nothing that stops a programmer from passing references to mutable data. In that case mutability &quot;leaks&quot; through to the pure function. Thus we end up with a function marked as pure, that can not be safely considered pure by the compiler. (Am I making any sense? Have I still not gotten your idea? Sorry if that&#039;s the case, It&#039;s rather late here now and my brain feels like jelly)

There&#039;s not much documentation to be found on the subject, but here&#039;s a couple of links you could check out:

http://www.digitalmars.com/d/2.0/function.html (Pure Functions)
http://www.digitalmars.com/d/2.0/const3.html (Const and Invariant)
And of course the links I gave in the article.

Best regards</description>
		<content:encoded><![CDATA[<p>Ok, I didn&#8217;t get that (I&#8217;m a bit slow at times <img src='http://www.hans-eric.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ). But if one does what you suggests (pure keyword that only forbids global state access and calls to non-pure functions) there is nothing that stops a programmer from passing references to mutable data. In that case mutability &#8220;leaks&#8221; through to the pure function. Thus we end up with a function marked as pure, that can not be safely considered pure by the compiler. (Am I making any sense? Have I still not gotten your idea? Sorry if that&#8217;s the case, It&#8217;s rather late here now and my brain feels like jelly)</p>
<p>There&#8217;s not much documentation to be found on the subject, but here&#8217;s a couple of links you could check out:</p>
<p><a href="http://www.digitalmars.com/d/2.0/function.html" rel="nofollow">http://www.digitalmars.com/d/2.0/function.html</a> (Pure Functions)<br />
<a href="http://www.digitalmars.com/d/2.0/const3.html" rel="nofollow">http://www.digitalmars.com/d/2.0/const3.html</a> (Const and Invariant)<br />
And of course the links I gave in the article.</p>
<p>Best regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mort</title>
		<link>http://www.hans-eric.com/2008/07/30/functional-d-is-transitive-const-fundamental/comment-page-1/#comment-13214</link>
		<dc:creator>mort</dc:creator>
		<pubDate>Wed, 30 Jul 2008 20:40:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.hans-eric.com/?p=124#comment-13214</guid>
		<description>Hi.  I think I didn&#039;t get one idea across.  I&#039;m suggesting we keep the &#039;pure&#039; keyword, but all it does is forbids access to global state and calls to non-pure functions.  So I don&#039;t think your response to 3) applies to my proposal.  Figuring out that a function is pure (in your sense) is trivial:  it&#039;s marked pure *and* it&#039;s parameters are marked invariant.

Thus pure in my sense subsumes pure in yours, and is orthogonal to invariance of parameters (rather than implying invariance).

Regarding the optimizations that can be applied, I would observe that nothing is stopping the compiler from specializing every pure function to a faster version that&#039;s pure in your sense if all arguments are known to be invariant.

I look forward to reading more about this topic in the future - I&#039;ve bookmarked your page :).  BTW, is there a source you can link to for additional information on the semantics of &#039;pure&#039; in D?   Thanks!</description>
		<content:encoded><![CDATA[<p>Hi.  I think I didn&#8217;t get one idea across.  I&#8217;m suggesting we keep the &#8216;pure&#8217; keyword, but all it does is forbids access to global state and calls to non-pure functions.  So I don&#8217;t think your response to 3) applies to my proposal.  Figuring out that a function is pure (in your sense) is trivial:  it&#8217;s marked pure *and* it&#8217;s parameters are marked invariant.</p>
<p>Thus pure in my sense subsumes pure in yours, and is orthogonal to invariance of parameters (rather than implying invariance).</p>
<p>Regarding the optimizations that can be applied, I would observe that nothing is stopping the compiler from specializing every pure function to a faster version that&#8217;s pure in your sense if all arguments are known to be invariant.</p>
<p>I look forward to reading more about this topic in the future &#8211; I&#8217;ve bookmarked your page <img src='http://www.hans-eric.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .  BTW, is there a source you can link to for additional information on the semantics of &#8216;pure&#8217; in D?   Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

