12th chapter sequence expressions and optional workflows

Source: Internet
Author: User

12th chapter sequence expressions and optional workflows

This chapter describes

Generating and processing sequence values

Working with an F # sequence expression

Understanding lists and LINQ expressions

Implementing an F # calculation expression

Before we start discussing the sequence expression, we must know what the sequence is (sequence), which is also the mathematical F # term. A sequence is an ordered list that may contain infinite elements. It all sounds a little bit abstract, but don't worry, we're already familiar with this type, and it's:ienumerable<t> to express the same concept in. NET.

The main reason for having a ienumerable<t> type in the. NET Framework is that it provides a uniform way to handle collection data, such as arrays, dictionaries, mutable lists, and immutable F # lists. In F #, we'll discuss the sequence because it's a more generic term. A sequence can represent a collection of finite elements, or it can be dynamically generated and restored when needed. We will learn the infinite sequence, which may sound scholarly, but it can also be useful in practical applications.

Let's start with a look at how to create and process sequences. The traditional functional approach is to use higher-order functions, but modern languages often provide an easier way. In C #, we can use iterations to generate sequences, use LINQ queries to process existing sequences, and the F # language unifies these two concepts to do most of the work with sequence expressions (sequence expressions).

In F #, the syntax of a sequence expression is not a single-purpose language feature designed for processing sequences; it's a (very useful!). The application of a more general structure, called a computational expression (computation expressions). The code that the calculation expression writes out looks like Plain F #, but behaves differently. In the case of a sequence expression, the resulting sequence is more than just a value, and we'll use the example to discuss it, logging it with a computed expression, and making it easier to handle option values.

Attention

In many ways, the calculation expression can customize the meaning of the code, but there are some limitations. In particular, code written with a computed expression must be compiled into. NET code to execute, and in which we can customize a few primitives (primitives). It cannot be used to manipulate code and execute in different environments, such as LINQ to SQL. To implement similar functionality in F #, we must combine the concepts of this chapter, a feature called F # Reference (F # Quotations), which is not discussed in this book, and can be found on the Web site of a reference.

We discuss the sequence first, and after we are familiar with the sequence expression, we discuss the calculation expression and the relationship to the LINQ query in C #. We will take the first step from the sequence and know how to create the sequence before using the sequence.

12th chapter sequence expressions and optional workflows

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.