Introduction to F #: Using functional programming techniques in the. NET Framework

Source: Internet
Author: User
Tags data structures xslt

This article discusses:

Install F #

F # language Basics

. NET Interoperability

Asynchronous F #

This article uses the following techniques:

. NET Framework, F #

Directory

Why do you use F #?

Install F #

Hello, F #

Let-expression

Keyword for

Pipeline

F # can also handle objects

Asynchronous F #

Working with F #

As a new member of the Microsoft®.net Framework family, F # provides type safety, performance, and the ability to work like a scripting language, all of which are part of the. NET environment. This functional language was invented by Don Syme of the Microsoft Institute as a OCAML syntax compatibility variant of the CLR, but F # has quickly shifted from research to practical applications.

As the concept of functional programming increasingly penetrates into mainstream languages, such as C # and Visual basic®, through technologies such as. NET generics and LINQ, F # is also increasingly well known in the. NET community--thus, in November 2007, Microsoft announced that F # Identified as a supported. NET programming language.

For years, it has been thought that functional language fields (ML, Haskell, etc.) are more suitable for academic research than for professional development. But that does not mean that these languages have no place to be. In fact, some of the important enhancements to. NET, such as generics, LINQ, PLINQ, and Futures, are all new applications of functional programming concepts to languages. The previous focus on these languages is largely due to the fact that their target platforms are not very much related to developers who write programs for Windows®, are not well integrated with the underlying platforms, or do not support key features such as relational database access, XML parsing, and out-of-process communication mechanisms.

However, the CLR and its "multiple languages, single platform" approach will make such languages more widely used in Windows development. And it's a logical cause for the attention of the workers on the frontline. F # is such a language. In this article, I'll introduce you to some of the basic concepts and benefits of F #. Then, to help you get a first look at F #, I'll detail its installation process and write a few simple small programs.

Why do you use F #?

For a small number of. NET programmers, learning a. NET Framework for a functional language will undoubtedly make it a big step forward in writing powerful software. For other programmers, the reasons for learning F # are different. What benefits can F # provide to developers?

With the popularization of multi-core CPUs, security concurrency has become the focus of the past three years. Functional languages advocate a fixed data structure that can be passed between threads and machines without worrying about thread safety or atomic access, a feature that developers can use to support concurrent operations. Functional languages can also make it easier to write libraries that support concurrent attributes, such as F # asynchronous workflows that are described later in this article.

Although it may not feel so strong for programmers who specialize in object-oriented development, in many cases, functional programs can actually simplify the writing and maintenance of some applications. For example, write a program that converts an XML document into other format data. Although it is entirely possible to write a C # program that parses an entire XML document and applies various if statements to determine what to do in different places in the document, the better approach is to write an Extensible Stylesheet Language Transformation (XSLT) program. Of course, XSLT certainly contains a large number of built-in function mechanisms, like SQL.

F # strongly recommends that you do not use null values (NULL), but instead promote the use of fixed-invariant data structures. These features reduce the amount of special code that you need to write to help reduce the frequency of programming errors.

Programs written using F # are also more concise. You can actually reduce what you type in two ways: fewer keystrokes and you have to advertise to the compiler that the variable type, parameter, or return type has fewer locations. This means that the code that needs to be maintained will be greatly reduced.

F # has a similar performance feature as C #. However, it has a much better performance feature than a language with similar simplicity (especially those of dynamic and scripting languages). And, F # also contains tools for viewing data interactively by writing program segments, similar to many dynamic languages.

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.