<?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>F# Guy - Koistya `Navin</title>
	<atom:link href="http://www.fsguy.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.fsguy.com</link>
	<description>Software Design Engineer since 2001</description>
	<lastBuildDate>Thu, 09 Sep 2010 15:14:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>New Property System and Property Extensions in C# 5.0</title>
		<link>http://www.fsguy.com/2010-09-09_property-extensions-in-csharp-5-0</link>
		<comments>http://www.fsguy.com/2010-09-09_property-extensions-in-csharp-5-0#comments</comments>
		<pubDate>Thu, 09 Sep 2010 02:32:05 +0000</pubDate>
		<dc:creator>Koistya `Navin</dc:creator>
				<category><![CDATA[General Category]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Property Extensions]]></category>
		<category><![CDATA[Property System]]></category>

		<guid isPermaLink="false">http://www.fsguy.com/?p=95</guid>
		<description><![CDATA[Programming languages evolve rapidly. New great features have been added to one of my favorite languages C# &#8211; lambda expressions, extension methods, dynamic type and many others. What can we expect next? One thing that comes to mind is a more advanced property system. WPF introduced a notion of DependencyProperty which has proved its success.]]></description>
			<content:encoded><![CDATA[<p>Programming languages evolve rapidly. New great features have been added to one of my favorite languages C# &#8211; <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx">lambda expressions</a>, <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx">extension methods</a>, <a href="http://msdn.microsoft.com/en-us/library/dd264736.aspx">dynamic type</a> and many others. What can we expect next?</p>
<p>One thing that comes to mind is a more advanced property system. <a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation">WPF</a> introduced a notion of <a href="http://msdn.microsoft.com/en-us/library/system.windows.dependencyproperty.aspx">DependencyProperty</a> which has proved its success. But.. can C# support something similar natively &#8211; properties which could store their states and dynamic meta data in addition to plain values? Why not?</p>
<p>Consider the following code sample:</p>
<pre class="brush: csharp; title: ;">
// A product type in this sample has a property Name of type String
var product = new Product();

// This will print &quot;Product.Name.IsDirty: False&quot;
Console.WriteLine(&quot;Product.Name.IsDirty: {0}&quot;, product.Name.IsDirty);

// Subscribe to an event
product.Name.BeforeChange += (s, e) =&gt; {
		if (e.NewValue == &quot;C++&quot;) { e.Cancel = true; }
	};

// Now let's try to update product's Name property
product.Name = &quot;C# 4.0 in a Nutshell&quot;;

// And now this will print &quot;Product.Name.IsDirty: True&quot;
Console.WriteLine(&quot;Product.Name.IsDirty: {0}&quot;, product.Name.IsDirty);

// Then when you try to save this product in database, it will be easier
// for your Store Repository to decide which fields must be saved
// and which can be skipped
storeRepository.Add(product);
storeRepository.SubmitChanges();
</pre>
<p>So far so good? But.. how this Product class is implemented? Actually not a magic.</p>
<p>Here is one of possible implementations &#8211; Codename &#8220;<strong>Properties inside properties</strong>&#8221; or &#8220;<strong>Nested Properties</strong>&#8221; in short:</p>
<pre class="brush: csharp; title: ;">
public interface IProduct
{
	string Name { get; set; bool IsDirty { get; } }
}

public class Product : IProduct
{
	private string name;
	private bool nameIsDirty;

	public string Name
	{
		get { return name; }
		set { if (name != value) { name = value; nameIsDirty = true; } }
		bool IsDirty { get { return nameIsDirty; } }
	}
}
</pre>
<p>Happy coding!</p>
<p><strong>P.S.</strong>: To tell you the truth, this is not the brightest example of what to expect in the next version of C#.  But if this blog post motivated you to creative thinking – then my goal is completed. Don’t be afraid to innovate; be different!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fsguy.com/2010-09-09_property-extensions-in-csharp-5-0/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Teaching programming language concepts with F# at Channel9</title>
		<link>http://www.fsguy.com/2010-09-02_teaching-programming-language-concepts-with-f-at-channel9</link>
		<comments>http://www.fsguy.com/2010-09-02_teaching-programming-language-concepts-with-f-at-channel9#comments</comments>
		<pubDate>Thu, 02 Sep 2010 10:17:59 +0000</pubDate>
		<dc:creator>Koistya `Navin</dc:creator>
				<category><![CDATA[General Category]]></category>

		<guid isPermaLink="false">http://www.fsguy.com/?p=79</guid>
		<description><![CDATA[Teaching Programming Language Concepts with F#, Part 1 In this first part, Peter introduces the curriculum, lecture plan and lecture notes for the course &#8220;Programs as data&#8221; that uses the functional programming concepts in F# to teach students language concepts and implementation details. Teaching Programming Language Concepts with F#, Part 2 In this second part,]]></description>
			<content:encoded><![CDATA[<p style="clear:both"><a href="http://channel9.msdn.com/posts/martinesmann/Teaching-programming-language-concepts-with-F-part-1/"><img src="http://www.fsguy.com/wp-content/uploads/2010/09/Teaching_Programming_Language_Concepts_with_FSharp_1.jpg" alt="" title="Teaching Programming Language Concepts with F#, Part 1" width="85" height="64" class="alignleft size-full wp-image-80" /></a><a href="http://channel9.msdn.com/posts/martinesmann/Teaching-programming-language-concepts-with-F-part-1/">Teaching Programming Language Concepts with F#, Part 1</a><br />
In this first part, Peter introduces the curriculum, lecture plan and lecture notes for the course &#8220;Programs as data&#8221; that uses the functional programming concepts in F# to teach students language concepts and implementation details.</p>
<p><a href="http://channel9.msdn.com/posts/martinesmann/Teaching-programming-language-concepts-with-F-part-2/"><img src="http://www.fsguy.com/wp-content/uploads/2010/09/Teaching_Programming_Language_Concepts_with_FSharp_2.jpg" alt="" title="Teaching Programming Language Concepts with F#, Part 2" width="85" height="64" class="alignleft size-full wp-image-81" /></a><a href="http://channel9.msdn.com/posts/martinesmann/Teaching-programming-language-concepts-with-F-part-2/">Teaching Programming Language Concepts with F#, Part 2</a><br />
In this second part, Peter finishes the first &#8220;demo&#8221; lecture of the F#-based programming language course.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fsguy.com/2010-09-02_teaching-programming-language-concepts-with-f-at-channel9/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pixel Fonts for Silverlight and WPF</title>
		<link>http://www.fsguy.com/2010-08-27_pixel-fonts-for-silverlight</link>
		<comments>http://www.fsguy.com/2010-08-27_pixel-fonts-for-silverlight#comments</comments>
		<pubDate>Fri, 27 Aug 2010 01:42:09 +0000</pubDate>
		<dc:creator>Koistya `Navin</dc:creator>
				<category><![CDATA[General Category]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Pixel Fonts]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.fsguy.com/?p=64</guid>
		<description><![CDATA[Just have created a custom TextBlock control which is able to render text by using pixel font and anti-aliasing turned of. Enjoy! Pixel Fonts for Silverlight and WPF at CodePlex]]></description>
			<content:encoded><![CDATA[<p>Just have created a custom TextBlock control which is able to render text by using pixel font and anti-aliasing turned of. Enjoy!</p>
<p><a href="http://pixelfonts.codeplex.com/"><img src="http://www.fsguy.com/wp-content/uploads/2010/08/PixelText.png" alt="Pixel Fonts for Silverlight" title="Pixel Fonts for Silverlight" width="551" height="144" class="alignnone size-full wp-image-66" /></a></p>
<p><a href="http://pixelfonts.codeplex.com/">Pixel Fonts for Silverlight and WPF</a> at CodePlex</p>
]]></content:encoded>
			<wfw:commentRss>http://www.fsguy.com/2010-08-27_pixel-fonts-for-silverlight/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to download stock quotes from Google Finance with F#</title>
		<link>http://www.fsguy.com/2010-08-24_how-to-download-stock-quotes-from-google-finance-with-fsharp</link>
		<comments>http://www.fsguy.com/2010-08-24_how-to-download-stock-quotes-from-google-finance-with-fsharp#comments</comments>
		<pubDate>Tue, 24 Aug 2010 00:39:32 +0000</pubDate>
		<dc:creator>Koistya `Navin</dc:creator>
				<category><![CDATA[General Category]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Stocks]]></category>

		<guid isPermaLink="false">http://www.fsguy.com/?p=7</guid>
		<description><![CDATA[In this blog post I want to show you by sample how to use asynchronous workflows, parallel LINQ extensions and message-processing agents in F#. Let&#8217;s create a simple tool which should be able to download stock quotes from Google Finance Objectives It should work asynchronously The executing thread shouldn&#8217;t be blocked during download so we]]></description>
			<content:encoded><![CDATA[<p>In this blog post I want to show you by sample how to use asynchronous workflows, parallel LINQ extensions and message-processing agents in F#. Let&#8217;s create a simple tool which should be able to download stock quotes from Google Finance</p>
<p><a href="http://finance.google.com"><img src="http://www.fsguy.com/wp-content/uploads/2010/08/Google-Finance.png" alt="Google Finance" title="Google Finance" width="600" height="200" class="alignnone size-full wp-image-24" /></a></p>
<h4>Objectives</h4>
<ul>
<li><strong>It should work asynchronously</strong><br />
	The executing thread shouldn&#8217;t be blocked during download so we could run this operation even on a UI thread without locking it</li>
<li><strong>Stock quotes should be downloaded in parallel</strong><br />
	But no more than 5 download streams at any particular moment in time</li>
<li><strong>Downloaded quotes should be parsed in parallel</strong><br />
	In order to utilize the available hardware resources efficiently</li>
<li><strong>Log actions &#038; exceptions</strong><br />
	In this example we will log events by using <code>printfn</code>
</ul>
<h4>Implementation</h4>
<pre class="brush: fsharp; title: ;">
open System
open System.Net
open System.Web
open Microsoft.FSharp.Collections

/// Stock price quote record
type Quote = {
    Symbol : string
    Date   : DateTime
    Open   : float
    High   : float
    Low    : float
    Close  : float
    Volume : int64
}

/// Stock prices download manager
type QuotesDownloader() =

    // en-US CultureInfo used for data parsing
    let ci = System.Globalization.CultureInfo.GetCultureInfo(&quot;en-US&quot;)

    /// Download quotes for a given symbol
    member this.downloadQuotesAsync (symbol : string) = async {
        try
            let tickerUri = Uri(@&quot;http://www.google.com/finance/historical?q=&quot; + HttpUtility.UrlEncode(symbol) + &quot;&amp;output=csv&quot;)
            use webClient = new WebClient()
            let! csv = webClient.AsyncDownloadString(tickerUri)
            try
                let quotes =
                    csv.Split([|'\n'|], StringSplitOptions.RemoveEmptyEntries)
                    |&gt; Seq.skip 1   // skip header
                    |&gt; PSeq.map (fun line   -&gt; line.Split [|','|])
                    |&gt; PSeq.map (fun values -&gt;
                    {
                        Symbol  = symbol
                        Date    = DateTime.Parse (values.[0], ci)
                        Open    = Double.Parse   (values.[1], ci)
                        High    = Double.Parse   (values.[2], ci)
                        Low     = Double.Parse   (values.[3], ci)
                        Close   = Double.Parse   (values.[4], ci)
                        Volume  = Int64.Parse    (values.[5], ci)
                    })
                printfn &quot;Downloaded a list of quotes for %s symbol.&quot; symbol
                return Some(quotes)
            with
                ex -&gt;
                    printfn &quot;Failed to parse quotes for %s symbol. %s&quot; symbol ex.Message
                    return None
        with
            ex -&gt;
                printfn &quot;Failed to download quotes for %s symbol. %s&quot; symbol ex.Message
                return None }

    member this.worker n f =
        MailboxProcessor&lt;string&gt;.Start(fun inbox -&gt;
            let workers =
                Array.init n (fun i -&gt; MailboxProcessor&lt;string&gt;.Start(f))
            let rec loop i = async {
                let! msg = inbox.Receive()
                workers.[i].Post(msg)
                return! loop ((i + 1) % n)
            }
            loop 0
        )

    member this.agent =
        this.worker 5 (fun inbox -&gt;
            let rec loop() = async {
                let! msg = inbox.Receive()
                let! quote = this.downloadQuotesAsync msg
                return! loop()
            }
            loop()
        )

    /// Download quotes for a list of simbos
    member this.downloadQuotes (symbols : string list) =
        for symbol in symbols do
            this.agent.Post symbol

// Let's execute it
let quotesDownloader = QuotesDownloader()
quotesDownloader.downloadQuotes [ &quot;MSFT&quot;; &quot;GOOG&quot;;
    &quot;AAPL&quot;; &quot;T&quot;; &quot;CVX&quot;; &quot;XOM&quot;; &quot;GE&quot;; &quot;HBC&quot;; &quot;IBM&quot;; &quot;JNJ&quot;; &quot;JPM&quot;;
    &quot;PG&quot;; &quot;WMT&quot;; &quot;MMM&quot;; &quot;ABT&quot;; &quot;ACN&quot;; &quot;MO&quot;; &quot;AMZN&quot;; &quot;AXP&quot;; &quot;APA&quot;;
    &quot;BLK&quot;; &quot;CAT&quot;; &quot;CVX&quot;; &quot;CSCO&quot;; &quot;CVS&quot;; &quot;DELL&quot;; &quot;DVN&quot;; &quot;FDX&quot; ]
</pre>
<h4>See also</h4>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/dd233184.aspx">Records (F#)</a> at MSDN</li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd233182.aspx">Computation Expressions (F#)</a> at MSDN</li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd233250.aspx">Asynchronous Workflows (F#)</a> at MSDN</li>
<li><a href="http://blogs.msdn.com/b/dsyme/archive/2010/02/15/async-and-parallel-design-patterns-in-f-part-3-agents.aspx">Async and Parallel Design Patterns in F#: Agents</a> by Don Syme</li>
<li><a href="http://fsharppowerpack.codeplex.com/">The F# Power Pack</a> at CodePlex
</ul>
<p><small><a href="http://www.fsguy.com/wp-content/uploads/2010/08/QuotesDownloader.zip">Download Source Codes</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.fsguy.com/2010-08-24_how-to-download-stock-quotes-from-google-finance-with-fsharp/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

