<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.atalasoft.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Rick Minerich's Development Wonderland : csharp, lazy</title><link>http://www.atalasoft.com/cs/blogs/rickm/archive/tags/csharp/lazy/default.aspx</link><description>Tags: csharp, lazy</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Functional Discoveries in the Microsoft Sociocosm 02/20/2009</title><link>http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx</link><pubDate>Fri, 20 Feb 2009 17:41:00 GMT</pubDate><guid isPermaLink="false">647108ca-f046-4d8d-9feb-a7fbd2049b37:17518</guid><dc:creator>RickM</dc:creator><slash:comments>3</slash:comments><comments>http://www.atalasoft.com/cs/blogs/rickm/comments/17518.aspx</comments><wfw:commentRss>http://www.atalasoft.com/cs/blogs/rickm/commentrss.aspx?PostID=17518</wfw:commentRss><wfw:comment>http://www.atalasoft.com/cs/blogs/rickm/rsscomments.aspx?PostID=17518</wfw:comment><description>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;This week we have practical examples of Lazy Evaluation with Memoization, an interview with Don Syme and a discussion on the Visitor Pattern’s place in F#.&amp;#160; Also, any comments on the new title for my weekly posting would be appreciated. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Forum – &lt;a href="http://cs.hubfs.net/forums/thread/8896.aspx"&gt;Memoization and Lazy Evaluation in F# on HubFS&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;In this thread &lt;a href="http://lorgonblog.spaces.live.com/blog/"&gt;brianmcm (Brian McNamara)&lt;/a&gt; and &lt;a href="http://cs.hubfs.net/search/SearchResults.aspx?q=divisortheory"&gt;divisortheory&lt;/a&gt; (???) explore using &lt;a href="http://blogs.msdn.com/dsyme/archive/2007/05/31/a-sample-of-the-memoization-pattern-in-f.aspx"&gt;memorization&lt;/a&gt; and &lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/03/21/adventures-in-f-f-101-part-6-lazy-evaluation.aspx"&gt;LazyLists&lt;/a&gt; to optimize a &lt;a href="http://en.wikipedia.org/wiki/Trial_division"&gt;Trial Division&lt;/a&gt; driven prime generator.&amp;#160; It’s interesting to look at how their prime generator evolved over time as they incorporated these ideas and optimized.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Article – &lt;a href="http://www.computerworld.com.au/article/271034/-z_programming_languages_f"&gt;Kathryn Edwards interviews Don Syme on F# Development&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;In this technically light but still extremely interesting interview, Kathryn mainly directs the conversation in the direction of the development and adoption of the F# programming language.&amp;#160; The most interesting thing I gleaned from the interview?&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;One of the key designers of Haskell, Simon Peyton-Jones, is just down the corridor from me at Microsoft Research Cambridge and has been a great help with F#.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Perhaps my &lt;a href="http://www.atalasoft.com/cs/blogs/rickm/archive/2009/01/29/f-and-haskell-estranged-cousins.aspx"&gt;F#/Haskell genealogy graph&lt;/a&gt; needs an additional arrow.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Blog – &lt;a href="http://stepheneasey.wordpress.com/2009/02/12/visitor-pattern-in-c-and-f/"&gt;Stephen Easey’s (?) Visitor Patten in C# and F#&lt;/a&gt;&lt;/h3&gt;  &lt;p&gt;In this post Stephen explores the &lt;a href="http://www.primos.com.au/primos/Default.aspx?PageContentID=12&amp;amp;tabid=63"&gt;Visitor Patten&lt;/a&gt; in both C# and F#.&amp;#160; I always love to see examples of how much more beautiful and concise F# is than C#.&amp;#160; The 218 line C# implementation shown beside the same implementation in 64 lines of F# makes for a great comparison in this regard.&amp;#160; &lt;/p&gt;  &lt;p&gt;I agree with Stephen’s conclusion in that, given the purpose of the visitor pattern is to separate algorithm from object via a &lt;a href="http://en.wikipedia.org/wiki/Double_dispatch"&gt;double dispatch&lt;/a&gt; layer, in many situations the visitor pattern is unnecessary in F# because of its advanced pattern matching capabilities.&lt;/p&gt;  &lt;p&gt;However, I feel that he may not have considered the perspective of an API provider.&amp;#160; In this context, it may be desirable for the consumer of an API to be able to extend the dispatch process to handle new cases.&amp;#160; The issue with a single monolithic matching function is that all of the logic is contained within that single function and so the system is no longer nearly as open to extension.&amp;#160; This violation of the &lt;a href="http://en.wikipedia.org/wiki/Open/closed_principle"&gt;Open Closed Principle&lt;/a&gt; (which applies to building APIs in any type of language) will make for difficult to reuse software.&amp;#160; &lt;/p&gt;  &lt;p&gt;Perhaps a F# pattern matching equivalent could be made with lambda functions for each branch.&amp;#160; Lambdas could be curried into the matching function and so each branch could potentially be replaced with new logic by the consumer.&amp;#160; However, this is feels to me like reimplementing OO with FP constructs.&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx&amp;amp;;subject=Functional+Discoveries+in+the+Microsoft+Sociocosm+02%2f20%2f2009" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx&amp;amp;;title=Functional+Discoveries+in+the+Microsoft+Sociocosm+02%2f20%2f2009" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx&amp;amp;title=Functional+Discoveries+in+the+Microsoft+Sociocosm+02%2f20%2f2009" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx&amp;amp;;title=Functional+Discoveries+in+the+Microsoft+Sociocosm+02%2f20%2f2009" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx&amp;amp;;title=Functional+Discoveries+in+the+Microsoft+Sociocosm+02%2f20%2f2009&amp;amp;;top=1" target="_blank" title = "Post http://www.atalasoft.com/cs/blogs/rickm/archive/2009/02/20/functional-discoveries-in-the-microsoft-sociocosm-02-20-2009.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://www.atalasoft.com/cs/aggbug.aspx?PostID=17518" width="1" height="1"&gt;</description><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/F_2300_/default.aspx">F#</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/.NET/default.aspx">.NET</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/fsharp/default.aspx">fsharp</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/roundup/default.aspx">roundup</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/lazy+evaluation/default.aspx">lazy evaluation</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/interview/default.aspx">interview</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/memoization/default.aspx">memoization</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/don+syme/default.aspx">don syme</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/double+dispatch/default.aspx">double dispatch</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/visitor+pattern/default.aspx">visitor pattern</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/lazy/default.aspx">lazy</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/open+closed+principle/default.aspx">open closed principle</category><category domain="http://www.atalasoft.com/cs/blogs/rickm/archive/tags/csharp/default.aspx">csharp</category></item></channel></rss>