F# Programming

F# Programming

F# Programming
Автор: Wikibooks
Дата выхода: 2008
Издательство: Independent publishing
Количество страниц: 105
Размер файла: 561.9 KB
Тип файла: PDF
Добавил: Aleks-5
 Проверить на вирусы

Preface....7

What is Wikibooks?....7

What is this book?....7

Who are the authors?....7

Wikibooks in Class....7

Happy Reading!....8

Introduction....8

Introducing F#....8

A Brief History of F#....8

Why Learn F#?....8

References....9

F# Basics....10

Getting Set Up....10

Windows....10

Mac OSX, Linux and UNIX....11

Basic Concepts....11

Major Features....11

Functional Programming Contrasted with Imperative Programming....13

Structure of F# Programs....14

Working With Functions....16

Declaring Values and Functions....16

Declaring Variables....16

Declaring Functions....16

Pattern Matching Basics....19

Pattern Matching Syntax....19

Alternative Pattern Matching Syntax....20

Binding Variables with Pattern Matching....20

Pay Attention to F# Warnings....20

Recursion and Recursive Functions....21

Examples....21

Tail Recursion....22

Exercises....23

Additional Reading....23

Higher Order Functions....23

Familiar Higher Order Functions....23

The |> Operator....24

Anonymous Functions....25

Currying and Partial Functions....25

Immutable Data Structures....27

Option Types....27

Using Option Types....27

Pattern Matching Option Types....27

Other Functions in the Option Module....27

Tuples and Records....28

Defining Tuples....28

Defining Records....29

Lists....30

Creating Lists....30

Pattern Matching Lists....31

Using the List Module....32

Exercises....34

Sequences....35

Defining Sequences....35

Iterating Through Sequences Manually....36

The Seq Module....36

Sets and Maps....37

Sets....37

Maps....39

Set and Map Performance....40

Discriminated Unions....40

Creating Discriminated Unions....40

Union basics: an On/Off switch....40

Holding Data In Unions: a dimmer switch....40

Creating Trees....41

Generalizing Unions For All Datatypes....41

Examples....41

Additional Reading....42

Imperative Programming....43

Mutable Data....43

mutable Keyword....43

Ref cells....43

Encapsulating Mutable State....44

Control Flow....44

Imperative Programming in a Nutshell....44

if/then Decisions....45

for Loops Over Ranges....45

for Loops Over Collections and Sequences....45

while Loops....46

Arrays....46

Creating Arrays....46

Working With Arrays....46

Differences Between Arrays and Lists....49

Mutable Collections....50

List<'T> Class....50

LinkedList<'T> Class....50

HashSet<'T>, and Dictionary<'TKey, 'TValue> Classes....51

Differences Between .NET BCL and F# Collections....52

Basic I/O....52

Working with the Console....52

System.IO Namespace....53

Exception Handling....54

Try/With....54

Raising Exceptions....54

Try/Finally....54

Defining New Exceptions....55

Exception Handling Constructs....55

Object Oriented Programming....56

Operator Overloading....56

Using Operators....56

Operator Overloading....56

Defining New Operators....56

Classes....57

Defining an Object....57

Class Members....59

Generic classes....61

Pattern Matching Objects....61

Inheritance....62

Subclasses....62

Working With Subclasses....63

Interfaces....64

Defining Interfaces....64

Using Interfaces....64

Examples....66

Events....67

Defining Events....67

Adding Callbacks to Event Handlers....68

Working with EventHandlers Explicitly....68

Passing State To Callbacks....69

Retrieving State from Callers....70

Using the Event Module....71

Modules and Namespaces....72

Defining Modules....72

Defining Namespaces....73

F# Advanced....76

Units of Measure....76

Use Cases....76

Defining Units....77

Dimensionless Values....77

Generalizing Units of Measure....77

F# PowerPack....78

External Resources....78

Caching....78

Partial Functions....78

Memoization....78

Lazy Values....79

Active Patterns....79

Defining Active Patterns....79

Additional Resources....81

Advanced Data Structures....81

Stacks....81

Queues....82

Binary Search Trees....83

Lazy Data Structures....86

Additional Resources....87

Reflection....87

Inspecting Types....87

Microsoft.FSharp.Reflection Namespace....88

Working With Attributes....89

Computation Expressions....90

Monad Primer....90

Defining Computation Expressions....91

What are Computation Expressions Used For?....92

Additional Resources....92

Multi-threaded and Concurrent Applications....93

Async Workflows....93

Defining Async Workflows....93

Async Extensions Methods....94

Async Examples....94

Concurrency with Functional Programming....95

MailboxProcessor Class....96

Defining MailboxProcessors....96

MailboxProcessor Methods....97

Two-way Communication....97

MailboxProcessor Examples....97

F# Tools....99

Lexing and Parsing....99

Lexing and Parsing from a High-Level View....99

Extended Example: Parsing SQL....99

Text and image sources, contributors, and licenses....104

Text....104

Images....105

Content license....105

What is this book?

This book was generated by the volunteers at Wikibooks, a team of people from around the world with varying backgrounds. The people who wrote this book may not be experts in the field. Some may not even have a passing familiarity with it. The result of this is that some information in this book may be incorrect, out of place, or misleading. For this reason, you should never rely on a community-edited Wikibook when dealing in matters of medical, legal, financial, or other importance. Please see our disclaimer for more details on this.

Despite the warning of the last paragraph, however, books at Wikibooks are continuously edited and improved. If errors are found they can be corrected immediately. If you find a problem in one of our books, we ask that you be bold in fixing it. You don't need anybody’s permission to help or to make our books better.

Wikibooks runs off the assumption that many eyes can find many errors, and many able hands can fix them. Over time, with enough community involvement, the books at Wikibooks will become very high-quality indeed. You are invited to participate at Wikibooks to help make our books better. As you find problems in your book don't just complain about them: Log on and fix them! This is a kind of proactive and interactive reading experience that you probably aren't familiar with yet, so log on to http://en.wikibooks.org and take a look around at all the possibilities. We promise that we won't bite!

Who are the authors?

The volunteers at Wikibooks come from around the world and have a wide range of educational and professional backgrounds. They come to Wikibooks for different reasons, and perform different tasks. Some Wikibookians are prolific authors, some are perceptive editors, some fancy illustrators, others diligent organizers. Some Wikibookians find and remove spam, vandalism, and other nonsense as it appears. Most Wikibookians perform a combination of these jobs.

It’s difficult to say who are the authors for any particular book, because so many hands have touched it and so many changes have been made over time. It’s not unheard of for a book to have been edited thousands of times by hundreds of authors and editors. You could be one of them too, if you're interested in helping out. 


Похожее:

Список отзывов:

Нет отзывов к книге.