<?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>Jim O'Neil's Blog : F#</title><link>http://blogs.msdn.com/jimoneil/archive/tags/F_2300_/default.aspx</link><description>Tags: F#</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Parallel Programming For Newbs: F# User Group 12/7</title><link>http://blogs.msdn.com/jimoneil/archive/2009/12/07/parallel-programming-for-newbs-f-user-group-12-7.aspx</link><pubDate>Mon, 07 Dec 2009 05:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9933228</guid><dc:creator>joneil</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jimoneil/comments/9933228.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jimoneil/commentrss.aspx?PostID=9933228</wfw:commentRss><description>&lt;p&gt;Developing applications for multicore machines is no longer an “if”, but rather a “when”, and the “when” is fast approaching (some would say it’s now).&amp;#160; Those of you following &lt;a href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx" target="_blank"&gt;Visual Studio 2010&lt;/a&gt; through its CTP and beta cycles ar&lt;a href="http://www.fsug.org"&gt;&lt;img style="border-right-width: 0px; margin: 10px 0px 0px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="FSUG" align="right" src="http://fsug.org/Portals/0/very%20small.png" /&gt;&lt;/a&gt;e aware of the functionality being added to .NET 4.0 and the IDE to better support you as you code parallel constructs in your choice of languages.&amp;#160; You may also be aware that Visual Studio 2010 marks the debut of F# as a bona fide .NET language, and that F# (and functional programming languages in general) are focused on abstracting complexities like parallel application development.&lt;/p&gt;  &lt;p&gt;So it’s a perfect storm of sorts as co-leader Talbott Crowell leads an interactive meeting of the &lt;a href="http://fsug.org"&gt;New England F# User Group&lt;/a&gt; tonight (December 7th) from 6:30 to 8:30 at the &lt;a href="http://microsoftcambridge.com" target="_blank"&gt;New England Research and Development (NERD) Center&lt;/a&gt; in Cambridge.&lt;/p&gt;  &lt;p&gt;Bring your laptop, so you can actively participate in the discussion, which will focus on the following goals:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Tackling many-core programming the easy way &lt;/li&gt;    &lt;li&gt;Providing a way to parallelize tasks without the heavy lifting &lt;/li&gt;    &lt;li&gt;Deciding which F# constructs are appropriate for various scenarios &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9933228" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jimoneil/archive/tags/User+Group/default.aspx">User Group</category><category domain="http://blogs.msdn.com/jimoneil/archive/tags/Massachusetts/default.aspx">Massachusetts</category><category domain="http://blogs.msdn.com/jimoneil/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>F is for… F#</title><link>http://blogs.msdn.com/jimoneil/archive/2009/02/09/f-is-for-f.aspx</link><pubDate>Mon, 09 Feb 2009 08:31:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9408023</guid><dc:creator>joneil</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jimoneil/comments/9408023.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jimoneil/commentrss.aspx?PostID=9408023</wfw:commentRss><description>&lt;p&gt;&lt;img style="border-right-width: 0px; margin: 0px 15px 5px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="F" border="0" alt="F" align="left" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/f_3.gif" width="52" height="75" /&gt; F# is the new kid on the block in terms of .NET languages.&amp;#160; Currently in &lt;a href="http://blogs.msdn.com/dsyme/archive/2008/08/29/the-f-september-2008-ctp-is-now-available.aspx"&gt;CTP form&lt;/a&gt;, it will be one of the .NET languages proper with the release of Visual Studio 2010 and the .NET Framework 4.0.&lt;/p&gt;  &lt;p&gt;What makes F# different is its focus on being a functional language: F# is all about writing a program that indicates &lt;strong&gt;what&lt;/strong&gt; you want to do, not &lt;strong&gt;how&lt;/strong&gt; you want to do it (as imperative languages do).&amp;#160; Functional languages in general have found favor in scientific and academic applications; however, they are by no means restricted to that domain.&amp;#160; F# is actually a multi-paradigm language, meaning you can include imperative and object-oriented programming concepts as well, which bodes well for its adoption in more mainstream business applications.&lt;/p&gt;  &lt;p&gt;There are a number of functional programming languages out there now, including &lt;a href="http://www.haskell.org/"&gt;Haskell&lt;/a&gt;, &lt;a href="http://www.ecma-international.org/publications/standards/Ecma-367.htm"&gt;Eiffel&lt;/a&gt;, &lt;a href="http://groups.csail.mit.edu/mac/projects/scheme/"&gt;Scheme&lt;/a&gt;, and &lt;a href="http://caml.inria.fr/"&gt;OCaml&lt;/a&gt; (with which F# shares its core language).&amp;#160; One that you’re probably familiar with is SQL (Structured Query Language).&amp;#160; Think about it, when you issue a SQL SELECT statement, you’re essentially expressing what you want, and how you get it is often a black-box operation carried out through the backend database’s query processor and optimization engine.&amp;#160; &lt;a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx"&gt;LINQ&lt;/a&gt; (Language Integrated Query), which was added to the .NET Framework 3.5, similarly incorporates functional programming ideals.&lt;/p&gt;  &lt;p&gt;One of the quickest ways to get started with F# is via &lt;em&gt;F# Interactive&lt;/em&gt;, a Read-Evaluate-Print-Loop (REPL) tool for executing F# code.&amp;#160; F# Interactive is part of the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=61ad6924-93ad-48dc-8c67-60f7e7803d3c&amp;amp;displaylang=en"&gt;CTP download&lt;/a&gt; and can be run as a command line interface or from within Visual Studio (from the View-&amp;gt;Other Windows menu).&lt;/p&gt;  &lt;p&gt;Some of the core features (well, the ones I found exceptionally cool) of F# include&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;type inference&lt;/strong&gt;:&amp;#160; F# is a strongly-typed language; however, data types don’t need to be specified explicitly, since they can be inferred at compilation time.&amp;#160; For example, below &lt;code&gt;x&lt;/code&gt; is set to an integer and &lt;code&gt;y&lt;/code&gt; to a string; note the error that occurs when trying to set &lt;code&gt;z&lt;/code&gt; to a concatenation of the two.&amp;#160; [The double-semicolon is used as a statement terminator here]. &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="" border="0" alt="" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/image_3.png" width="481" height="242" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;immutability&lt;/strong&gt;: One of the hallmarks of functional languages is the avoidance of state and mutable data.&amp;#160; Immutable values have benefits in that they can actually prevent certain types of bugs, and they are inherently thread-safe, making code much easier to parallelize.&amp;#160; &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="" border="0" alt="" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/image_9.png" width="481" height="77" /&gt;&lt;/p&gt;    &lt;p&gt;Given the multi-paradigm nature of F#, you can, however, use mutable variables (via the &lt;code&gt;mutable&lt;/code&gt; keyword) as the snippet below shows. &lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="" border="0" alt="" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/image_8.png" width="481" height="100" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;Another way to handle mutable values is via reference variables, which create a pointer to memory on the heap that you can then modify via the := operator, for example:&lt;/p&gt;    &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="" border="0" alt="" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/image_12.png" width="481" height="103" /&gt;&amp;#160;&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;tuples:&lt;/strong&gt; Tuples are an ordered collection of values that you can treat as a unit without having to define a new type.&amp;#160; In the sample below: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;   &lt;br /&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;The first line defines a tuple, &lt;code&gt;myName&lt;/code&gt;, consisting of two string values, here my first and last name.&amp;#160; &lt;/li&gt;      &lt;li&gt;The second line defines a function that takes one argument, a 2-tuple.&amp;#160; Here, &lt;code&gt;first&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt; refer to the two values within the tuple (a function declared with two arguments would not use parentheses nor a comma separator).&amp;#160; &lt;/li&gt;      &lt;li&gt;The final line prints out the result of the function, namely a string with the first and last names of the tuple concatenated with a space separator. &lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="" border="0" alt="" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/image_15.png" width="481" height="72" /&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;first-order function passing:&lt;/strong&gt; First-order functions (namely functions whose parameters and return value are NOT functions themselves) are also known as lambda expressions.&amp;#160; When coupled with the F# &lt;code&gt;List&lt;/code&gt; collection type, for example, you can do some nifty things like find the palindromes in a list of strings with a single line of code! &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="" border="0" alt="" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/image_18.png" width="480" height="131" /&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Pipe and forward:&lt;/strong&gt; In the above snippet, note the use of the pipe-and-forward operator (|&amp;gt;) which is a shortcut for passing arguments to methods.&amp;#160; In that sample, we could have done without it (and just called &lt;code&gt;List.filter(…) strList&lt;/code&gt;), but it enables you to conveniently string together a series of methods that successively transform the input.&amp;#160; For instance, here we extend that snippet to get the &lt;em&gt;number&lt;/em&gt; of palindromes in the list: &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="" border="0" alt="" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/image_21.png" width="481" height="134" /&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;white space:&lt;/strong&gt; One interesting facet of F# that takes a little getting used to is the notion of significant white-space.&amp;#160; With conditional statements, for instance, there is no equivalent of an “END IF” or curly braces to delimit statement blocks.&amp;#160; In F#, the scope of the statement is determined by the indentation.&amp;#160; Note the difference in output in the following:&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/image_26.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="" border="0" alt="" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/FisforF_F619/image_thumb_8.png" width="351" height="262" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I’ve really just scratched the surface here, and since F# is a .NET language, you’ll be able to leverage the classes you’re accustomed to in C# and VB.NET (note, we used &lt;code&gt;System.String.ToCharArray()&lt;/code&gt;in the palindrome sample above).&amp;#160; There’s support for conditionals and loops, which themselves are functions, as well as exception handling via syntax similar to try-catch-finally.&amp;#160; One particularly powerful feature I didn’t touch upon above is the &lt;code&gt;match&lt;/code&gt; expression which is commonly used with yet another language concept known as &lt;a href="http://lorgonblog.spaces.live.com/blog/cns!701679AD17B6D310!172.entry"&gt;discriminated unions&lt;/a&gt;.&amp;#160; In fact, as you get more familiar with the functional programming style, you’ll find that pattern matching (via &lt;code&gt;match&lt;/code&gt;) and recursion will take the place of many instances where you’d rely on if’s and for loops in imperative languages.&lt;/p&gt;  &lt;p&gt;For a deeper dive into F#, check out these great on-line F# resources:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/chrsmith/archive/2008/05/02/f-in-20-minutes-part-i.aspx"&gt;Chris Smith’s &lt;em&gt;“F# in 20 Minutes”&lt;/em&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx"&gt;Microsoft F# Developer Center&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://cs.hubfs.net/"&gt;hubFS: THE Place for F#&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Blogs      &lt;ul&gt;       &lt;li&gt;&lt;a href="http://blogs.msdn.com/chrsmith"&gt;Chris Smith&lt;/a&gt; &lt;/li&gt;        &lt;li&gt;&lt;a href="http://blogs.msdn.com/dsyme/"&gt;Don Syme&lt;/a&gt; &lt;/li&gt;        &lt;li&gt;&lt;a href="http://lorgonblog.spaces.live.com/blog/"&gt;Brian McNamara&lt;/a&gt; &lt;/li&gt;        &lt;li&gt;&lt;a href="http://blogs.msdn.com/andrewkennedy/"&gt;Andrew Kennedy&lt;/a&gt; &lt;/li&gt;        &lt;li&gt;&lt;a href="http://weblogs.asp.net/podwysocki/"&gt;Matt Podwysocki&lt;/a&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9408023" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jimoneil/archive/tags/A-to-Z/default.aspx">A-to-Z</category><category domain="http://blogs.msdn.com/jimoneil/archive/tags/F_2300_/default.aspx">F#</category></item></channel></rss>