Book contents
- Frontmatter
- Contents
- Preface
- 1 Getting started
- 2 Values, operators, expressions and functions
- 3 Tuples, records and tagged values
- 4 Lists
- 5 Collections: Lists, maps and sets
- 6 Finite trees
- 7 Modules
- 8 Imperative features
- 9 Efficiency
- 10 Text processing programs
- 11 Sequences
- 12 Computation expressions
- 13 Asynchronous and parallel computations
- Appendix A Programs from the keyword example
- Appendix B The TextProcessing library
- Appendix C The dialogue program from Chapter 13
- References
- Index
11 - Sequences
Published online by Cambridge University Press: 05 May 2013
- Frontmatter
- Contents
- Preface
- 1 Getting started
- 2 Values, operators, expressions and functions
- 3 Tuples, records and tagged values
- 4 Lists
- 5 Collections: Lists, maps and sets
- 6 Finite trees
- 7 Modules
- 8 Imperative features
- 9 Efficiency
- 10 Text processing programs
- 11 Sequences
- 12 Computation expressions
- 13 Asynchronous and parallel computations
- Appendix A Programs from the keyword example
- Appendix B The TextProcessing library
- Appendix C The dialogue program from Chapter 13
- References
- Index
Summary
A sequence is a possibly infinite, ordered collection of elements seq [eo; e1;…]. The elements of a sequence are computed on demand only, as it would make no sense to actually compute an infinite sequence. Thus, at any stage in a computation, just a finite portion of the sequence has been computed.
The notion of a sequence provides a useful abstraction in a variety of applications where you are dealing with elements that should be processed one after the other. Sequences are supported by the collection library of F# and many of the library functions on lists presented in Chapter 5 have similar sequence variants. Furthermore, sequences can be defined in F# using sequence expressions, defining a process for generating the elements.
The type seq<′a> is a synonym for the .NET type IEnumerable<′a> and any .NET framework type that implements this interface can be used as a sequence. One consequence of this is, for the F# language, that lists and arrays (that are specializations of sequences) can be used as sequence arguments for the functions in the Seq library. Another consequence is that results from the Language-Integrated Query or LINQ component of the .NET framework can be viewed as F# sequences. LINQ gives query support for different kinds of sources like SQL databases and XML repositories.
- Type
- Chapter
- Information
- Functional Programming Using F# , pp. 251 - 278Publisher: Cambridge University PressPrint publication year: 2013