<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Anay Kamat's Weblog &#187; functional programming</title>
	<atom:link href="http://anaykamat.com/tag/functional-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://anaykamat.com</link>
	<description>Technology, Programming, Career, Fun, Friends And Thoughts</description>
	<lastBuildDate>Wed, 25 Aug 2010 12:20:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Y-Combinator in C#</title>
		<link>http://anaykamat.com/2009/04/08/y-combinator-in-csharp/</link>
		<comments>http://anaykamat.com/2009/04/08/y-combinator-in-csharp/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 14:19:26 +0000</pubDate>
		<dc:creator>Anay</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technologies]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://anaykamat.com/?p=58</guid>
		<description><![CDATA[For last few days, I was trying to use lambda feature of C# to implement Y-Combinator. After few trial and errors, I was able to implement it in C# 3.5. I&#8217;m currently posting the code here and in my next blog, I&#8217;ll explain how I derived it. In this code, Y-Combinator function, is used to [...]]]></description>
			<content:encoded><![CDATA[<p>For last few days, I was trying to use lambda feature of C# to implement Y-Combinator. After few trial and errors, I was able to implement it in C# 3.5. I&#8217;m currently posting the code here and in my next blog, I&#8217;ll explain how I derived it.</p>
<p>In this code, Y-Combinator function, is used to implement anonymous recursive-factorial function called &#8216;factorial&#8217;.</p>
<pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YCombinator
{
    class Program
    {
        delegate Func RecursiveFunction(RecursiveFunction f);

        static void Main(string[] args)
        {

            Func, Func&gt;, Func&gt; Y = (f) =&gt;
            {
                RecursiveFunction function = (h) =&gt;
                {
                    return (x) =&gt;
                    {
                        return f(h(h))(x);
                    };
                };
                return function(function);
            };

            Func factorial = Y(function=&gt;
            {
                return x =&gt;
                {
                    return x == 0 ? 1 : x * function(x - 1);
                };
            });
            Console.WriteLine(factorial(5));
            Console.ReadLine();
        }
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://anaykamat.com/2009/04/08/y-combinator-in-csharp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
