<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/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>F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx</link><description>Now that we have covered the basics, in minutes 8 - 14 we will cover the foundational concepts and types in F#. By the end of Part II you should be able to read F# code reasonably well. Immutability You may have noticed that I’ve been using the term ‘value’</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#8483829</link><pubDate>Sat, 10 May 2008 17:31:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8483829</guid><dc:creator>Paczesiowa</dc:creator><description>&lt;p&gt;let result = 512 |&amp;gt; square |&amp;gt; toStr |&amp;gt; ref&lt;/p&gt;
&lt;p&gt;should be rev &lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#8483980</link><pubDate>Sat, 10 May 2008 19:18:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8483980</guid><dc:creator>ChrSmith</dc:creator><description>&lt;p&gt;Doh. Fixed it, thanks.&lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#8509074</link><pubDate>Thu, 15 May 2008 23:00:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8509074</guid><dc:creator>Keith</dc:creator><description>&lt;p&gt;512^2 = 262144&lt;/p&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p&gt;32^2 = 1024&lt;/p&gt;
&lt;p&gt;Great series, btw!&lt;/p&gt;
</description></item><item><title>F# 20分钟快速上手（二）</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#8846349</link><pubDate>Sun, 10 Aug 2008 12:09:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8846349</guid><dc:creator>Anders Cui</dc:creator><description>&lt;p&gt;在上篇文章里，我们写出了F#的第一个程序，本文我们来看一些F#语言的核心部分，包括值的不变性，模块，Tuple，柯里化，Union类型，模式匹配，Record类型，序列和集合等内容，读完此文后，希望能让您对F#有个整体的认识。&lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#8953073</link><pubDate>Mon, 15 Sep 2008 23:43:01 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8953073</guid><dc:creator>Kurt</dc:creator><description>&lt;p&gt;Thanks for the articles. Is part III available? I can't seem to find the advanced topics article.&lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#8969336</link><pubDate>Mon, 29 Sep 2008 22:03:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8969336</guid><dc:creator>Sam Stokes</dc:creator><description>&lt;p&gt;Wow, this is a great way to learn Data Structures! &amp;nbsp;I have ordered the F# for Scienctists, thanks for the review. &amp;nbsp;I am working to figure out how to demo F# to non-CS faculty for simulations, etc.&lt;/p&gt;
</description></item><item><title>F# 20分钟快速上手（二）</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9001855</link><pubDate>Thu, 16 Oct 2008 17:36:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9001855</guid><dc:creator>心界使者</dc:creator><description>&lt;p&gt;原文链接：&lt;a rel="nofollow" target="_new" href="http://www.cnblogs.com/anderslly/archive/2008/08/10/fs-in-20-minutes-core.html"&gt;http://www.cnblogs.com/anderslly/archive/2008/08/10/fs-in-20-minutes-core.html&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9016342</link><pubDate>Sun, 26 Oct 2008 01:03:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9016342</guid><dc:creator>Rick Love</dc:creator><description>&lt;p&gt;I was comparing F# features to C# 3.5, to see how they compare. &lt;/p&gt;
&lt;p&gt;One thing that interested me is the forward pipe operator (which would be nice for C# to implement next version).&lt;/p&gt;
&lt;p&gt;However, it can be simulated with Extension Methods:&lt;/p&gt;
&lt;p&gt;public static class FunctionalPipeExtensions&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static void Test()&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;var doSquare = new Func&amp;lt;int, int&amp;gt;(n =&amp;gt; n * n);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;var doReverse = new Func&amp;lt;string, string&amp;gt;(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;s =&amp;gt; s.ToCharArray()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Pipe(Array.Reverse)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Pipe(ca =&amp;gt; new String(ca))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;var strRev = (4)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Pipe(doSquare)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;.ToString()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Pipe(doReverse);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;var numberRev = strRev.Pipe(s =&amp;gt; int.Parse(s));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;// numberRev == 61&lt;/p&gt;
&lt;p&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static TResult Pipe&amp;lt;T, TResult&amp;gt;(this T input, Func&amp;lt;T, TResult&amp;gt; doFunc)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return doFunc(input);&lt;/p&gt;
&lt;p&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static T Pipe&amp;lt;T&amp;gt;(this T input, Action&amp;lt;T&amp;gt; doFunc)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;doFunc(input);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return input;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;I considered naming this method &amp;quot;_&amp;quot; or &amp;quot;_P_&amp;quot; instead of &amp;quot;Pipe&amp;quot; because it is a strange but useful little guy in C#.&lt;/p&gt;
&lt;p&gt;Especially notice the 2nd Pipe method which allows one to use a void returning method (which changes the internal state of the mutable object), but continue the series of method calls.&lt;/p&gt;
&lt;p&gt;Also, object methods and extension methods fit right into the pipeline.&lt;/p&gt;
&lt;p&gt;Some limitations:&lt;/p&gt;
&lt;p&gt;- Cannot assign lambda expression to an implicitly-typed local variable.&lt;/p&gt;
&lt;p&gt;- The C# compiler will not automatically map a method to an equivalent delegate Func&amp;lt;T,TResult&amp;gt;, etc. The types on the generic method must be given, or a lambda expression must be used to wrap the method call.&lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9152886</link><pubDate>Fri, 28 Nov 2008 22:09:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9152886</guid><dc:creator>Jarlac</dc:creator><description>&lt;p&gt;let result = 512 |&amp;gt; square |&amp;gt; toStr |&amp;gt; rev&lt;/p&gt;
&lt;p&gt;It looks like RPN (Reverse Polish Notation) to me.&lt;/p&gt;
&lt;p&gt;But from the definition: let (|&amp;gt;) x f = f x ,&lt;/p&gt;
&lt;p&gt;I guess it only takes one parameter right? Is there a way to pass more parameters before the function call??&lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9153564</link><pubDate>Sat, 29 Nov 2008 01:17:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9153564</guid><dc:creator>ChrSmith</dc:creator><description>&lt;p&gt;Using the pipe forward operator (|&amp;gt;) you can pipe a single value to a function that takes any number of parameters. But from the definition it looks as if 'f' only takes one.&lt;/p&gt;
&lt;p&gt;The trick is to use function currying. Let's say you have a function that takes three parameters:&lt;/p&gt;
&lt;p&gt;let f x y z = ...&lt;/p&gt;
&lt;p&gt;If you curry f by providing two of its parameters:&lt;/p&gt;
&lt;p&gt;let g = f x y&lt;/p&gt;
&lt;p&gt;The result is a function that takes a single parameter (what would have been z).&lt;/p&gt;
&lt;p&gt;So to use the pipe forward operator with a function that takes multiple args you end up with something like this:&lt;/p&gt;
&lt;p&gt;z |&amp;gt; f x y&lt;/p&gt;
&lt;p&gt;The only downside is that the pipe forward operator only works for curryable functions. If a function takes a tuple:&lt;/p&gt;
&lt;p&gt;f (x, y, z)&lt;/p&gt;
&lt;p&gt;Then you will not be able to pipe data into it. &lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9165956</link><pubDate>Tue, 02 Dec 2008 23:04:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9165956</guid><dc:creator>Dustin</dc:creator><description>&lt;p&gt;The only downside is that the pipe forward operator only works for curryable functions. If a function takes a tuple:&lt;/p&gt;
&lt;p&gt;f (x, y, z)&lt;/p&gt;
&lt;p&gt;We can't? &amp;nbsp;Perhaps I'm misunderstanding how a function is defined in F# (I'm using the longest of a few ways, I know):&lt;/p&gt;
&lt;p&gt;let sum3 = function&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;| (x, y, z) -&amp;gt; x + y + z;;&lt;/p&gt;
&lt;p&gt;let my_tuple = (1, 2, 3);;&lt;/p&gt;
&lt;p&gt;let result = my_tuple |&amp;gt; sum3;;&lt;/p&gt;
&lt;p&gt;printf &amp;quot;%A\n&amp;quot; result;;&lt;/p&gt;
&lt;p&gt;That prints 6, right? &amp;nbsp;Perhaps I misinterpreted your statement, Chris?&lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9181539</link><pubDate>Sun, 07 Dec 2008 01:25:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9181539</guid><dc:creator>Ryan</dc:creator><description>&lt;p&gt;Curryable functions and tuple functions have different signatures. The key is to understand that functions are themselves values. Let's compare:&lt;/p&gt;
&lt;p&gt;&amp;gt; let sum3tuple (x, y, z) = x + y + z;;&lt;/p&gt;
&lt;p&gt;val sum3tuple : int * int * int -&amp;gt; int&lt;/p&gt;
&lt;p&gt;&amp;gt; let sum3curry x y z = x + y + z;;&lt;/p&gt;
&lt;p&gt;val sum3curry : int -&amp;gt; int -&amp;gt; int -&amp;gt; int&lt;/p&gt;
&lt;p&gt;This shows that sum3tuple accepts a triple of integers and returns an integer. It's used like this:&lt;/p&gt;
&lt;p&gt;&amp;gt; sum3tuple (1, 2, 3);;&lt;/p&gt;
&lt;p&gt;val it : int = 6&lt;/p&gt;
&lt;p&gt;The tuple is a single value that must be constructed with parentheses because syntactically that is the only way to construct a tuple.&lt;/p&gt;
&lt;p&gt;Whereas sum3curry accepts an integer and returns a function with the signature (int -&amp;gt; int -&amp;gt; int). The returned function is itself a function that accepts an integer and returns a function that accepts and integer and returns an integer. Confused yet?&lt;/p&gt;
&lt;p&gt;Here's how it works:&lt;/p&gt;
&lt;p&gt;&amp;gt; sum3curry 1 2 3;;&lt;/p&gt;
&lt;p&gt;val it : int = 6&lt;/p&gt;
&lt;p&gt;I can add parenthetical nesting to emphasize how this works:&lt;/p&gt;
&lt;p&gt;&amp;gt; ((sum3curry 1) 2) 3;;&lt;/p&gt;
&lt;p&gt;val it : int = 6&lt;/p&gt;
&lt;p&gt;In this example, (sum3curry 1) returns a function which is then passed the argument 2. This returns another function that is passed the argument 3. Finally, this function returns an integer.&lt;/p&gt;
&lt;p&gt;The |&amp;gt; operator just lets us flip this around backward and put the inputs to the function first:&lt;/p&gt;
&lt;p&gt;&amp;gt; 3 |&amp;gt; (2 |&amp;gt; (1 |&amp;gt; sum3curry));;&lt;/p&gt;
&lt;p&gt;val it : int = 6&lt;/p&gt;
&lt;p&gt;Note that the parenthetical grouping is required this time because the default precedence is left-to-right.&lt;/p&gt;
&lt;p&gt;Incidentally, we can still use |&amp;gt; with the tuple version, we just can't split up the parameters:&lt;/p&gt;
&lt;p&gt;&amp;gt; (1, 2, 3) |&amp;gt; sum3tuple;; &lt;/p&gt;
&lt;p&gt;val it : int = 6&lt;/p&gt;
</description></item><item><title>re: F# in 20 Minutes – Part II</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9201488</link><pubDate>Fri, 12 Dec 2008 12:30:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9201488</guid><dc:creator>Steve</dc:creator><description>&lt;p&gt;And you can move between the curried world and the uncurried world using functions like:&lt;/p&gt;
&lt;p&gt;&amp;gt; let curry2 f x y = f (x, y);;&lt;/p&gt;
&lt;p&gt;val curry2 : ('a * 'b -&amp;gt; 'c) -&amp;gt; 'a -&amp;gt; 'b -&amp;gt; 'c&lt;/p&gt;
&lt;p&gt;&amp;gt; let uncurry2 f (x, y) = f x y;;&lt;/p&gt;
&lt;p&gt;val uncurry2 : ('a -&amp;gt; 'b -&amp;gt; 'c) -&amp;gt; 'a * 'b -&amp;gt; 'c&lt;/p&gt;
</description></item><item><title>F#, Imperative Languages and Identifiers</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9256189</link><pubDate>Tue, 30 Dec 2008 00:21:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9256189</guid><dc:creator>Sam Stokes on Research in your life and studies</dc:creator><description>&lt;p&gt;OMG! I got pulled off my usual job of doing a bunch of things and have been focused on getting students&lt;/p&gt;
</description></item><item><title>re: Immutability</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9391792</link><pubDate>Tue, 03 Feb 2009 01:37:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9391792</guid><dc:creator>beginner-1104</dc:creator><description>&lt;p&gt;I still don't get the immutability. In F# Interactive console I typed&lt;/p&gt;
&lt;p&gt;&amp;gt; let x = 3;;&lt;/p&gt;
&lt;p&gt;which evaluated x as&lt;/p&gt;
&lt;p&gt;val it : int = 3&lt;/p&gt;
&lt;p&gt;Then I typed &lt;/p&gt;
&lt;p&gt;&amp;gt; let x = 4;;&lt;/p&gt;
&lt;p&gt;First of all, I expected some kind of error message that x cannot be re-assigned or something like that. But it was accepted OK.&lt;/p&gt;
&lt;p&gt;Then, the evaluation of x was:&lt;/p&gt;
&lt;p&gt;val it : int = 4&lt;/p&gt;
&lt;p&gt;So, where is the immutablity? Do I miss something?&lt;/p&gt;
&lt;p&gt;Many thanks!&lt;/p&gt;
</description></item><item><title>re: re: Immutability</title><link>http://blogs.msdn.com/chrsmith/archive/2008/05/09/f-in-20-minutes-part-ii.aspx#9412896</link><pubDate>Wed, 11 Feb 2009 18:39:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9412896</guid><dc:creator>beginner-1104</dc:creator><description>&lt;p&gt;I found the answer to my above question at &lt;a rel="nofollow" target="_new" href="http://en.wikibooks.org/wiki/Haskell/Variables_and_functions"&gt;http://en.wikibooks.org/wiki/Haskell/Variables_and_functions&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>