F # Concise Tutorial one: F # and functional Programming Overview

Source: Internet
Author: User
Tags command line visual studio

F # is Microsoft. NET development platform of a programming language, its biggest feature is the introduction of functional programming (fp,functionalprogramming); F # is also excellent at supporting Object-oriented (OOP) programming, using the F # language, Developers have the freedom to choose functional programming or object-oriented programming to implement their projects. In addition, F # can also be associated with. NET platform, C #, VB and other programming languages closely combined.

In the context of CPU multi-core and cloud computing, functional programming can solve the problem of multiple concurrent operations (in terms of dealing with concurrent problems, object-oriented programming has some inherent defects, such as the side effects of class and instantiation process, For more information, refer to 51cto.com's video interview on Erlang, another functional programming language, "hot because of Concurrency: the" Live Cloud Computing ("Erlang expert Interview"). Microsoft has seen this trend, trying to promote the F # language created specifically for functional programming. NET platform in concurrent processing, multi-core concurrency, further enhance the productivity of developers and code efficiency. On the TechED in 2009, 51cto.com interviewed Microsoft MVP Zhao with a video about F # and functional programming, and we can interview video about the recent developments in F # and functional programming, please refer to the TechED 09 video interview: F # and functional programming languages.

F # Small background: Seemingly young F # has a history of nearly 10 years. Originally developed by Don Syme of Microsoft Research in 2002, F # launched its first version in 2005, and at the end of 2007, Microsoft declared F # into a product phase. In constant improvement, F # absorbs a number of benefits from C #, LINQ, and Haskell.

F # Programming starts

F # can run on platforms above version 2.0 of the. NET Framework. If your Visual Studio did not have F # installed before, you can obtain it from Microsoft F # Developer Center (http://msdn.microsoft.com/en-us/fsharp/default.aspx).

Can't exception, let's look at F # 's Hello World code:

#light

System.Console.WriteLine ("This is one Hello")

Printfn "This is another Hello"

After saving the code as a Hello.fs file, we need to build a. NET assembly on the command line by Fsc.exe compilation. The compiled code on the command line is as follows:

FSC Hello.fs

With the above code, we get the common executable (. exe file), which is the start of our F #--hello.exe.

F # Tip: F # is a compiled language on the. NET platform, but it can still run like a scripting language. You can use Visual Studio or Fsi.exe (the bin directory under the F # installation directory) for F # script execution.

Code interpretation

Let's take a closer look at the code in the Hello.fs file.

The program starts with "#light", and on the way to the future F #, we often see "#light"; most of the time, "#light" always appears at the beginning of the F # program, which is the identity of the F # Lightweight syntax; in the latest F # version, #light将作为默认选项.

"System.Console.WriteLine" calls one. NET base class (a friend familiar with C # or vb.net) is used to initialize some of the necessary functionality.

"PRINTFN" is a common function of F #, and he prints the parameters in double quotes to the console display.

Like the other program's Hello world, this F # code is straightforward and looks similar to Hello World written in other languages, but as a functional programming language, F # 's syntax and programming are very different. In next week's section, we'll drill down into F # programming to explain F # 's type system and compilation mechanism.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.