You are previewing Programming F# 3.0, 2nd Edition.

Programming F# 3.0, 2nd Edition

Cover of Programming F# 3.0, 2nd Edition by Chris Smith Published by O'Reilly Media, Inc.
  1. Programming F# 3.0
  2. Preface
    1. Introducing F#
    2. Who This Book Is For
    3. What You Need to Get Going
    4. How the Book Is Organized
      1. Part I
      2. Part II
      3. Part III
    5. Part IV
    6. Conventions Used in This Book
    7. Using Code Examples
    8. Safari® Books Online
    9. I’d Like to Hear from You
    10. Acknowledgments
  3. I. Multiparadigm Programming
    1. 1. Introduction to F#
      1. Getting to Know F#
      2. Visual Studio 11
      3. F# Interactive
      4. Managing F# Source Files
    2. 2. Fundamentals
      1. Primitive Types
      2. Comparison and Equality
      3. Functions
      4. Core Types
      5. Organizing F# Code
    3. 3. Functional Programming
      1. Understanding Functions
      2. Pattern Matching
      3. Discriminated Unions
      4. Records
      5. Lazy Evaluation
      6. Sequences
      7. Queries
    4. 4. Imperative Programming
      1. Understanding Memory in .NET
      2. Changing Values
      3. Units of Measure
      4. Arrays
      5. Mutable Collection Types
      6. Looping Constructs
      7. Exceptions
    5. 5. Object-Oriented Programming
      1. Programming with Objects
      2. Understanding System.Object
      3. Understanding Classes
      4. Methods and Properties
      5. Inheritance
    6. 6. .NET Programming
      1. The .NET Platform
      2. Interfaces
      3. Object Expressions
      4. Extension Methods
      5. Extending Modules
      6. Enumerations
      7. Structs
  4. II. Programming F#
    1. 7. Applied Functional Programming
      1. Active Patterns
      2. Using Modules
      3. Mastering Lists
      4. Tail Recursion
      5. Programming with Functions
      6. Functional Patterns
      7. Functional Data Structures
    2. 8. Applied Object-Oriented Programming
      1. Operators
      2. Generic Type Constraints
      3. Delegates and Events
      4. Events
    3. 9. Asynchronous and Parallel Programming
      1. Working with Threads
      2. Asynchronous Programming
      3. Asynchronous Workflows
      4. Parallel Programming
      5. Task Parallel Library
    4. 10. Scripting
      1. F# Script Files
      2. Directives
      3. F# Script Recipes
    5. 11. Data Processing
      1. Indexing
      2. Querying
  5. III. Extending the F# Language
    1. 12. Reflection
      1. Attributes
      2. Type Reflection
      3. Dynamic Instantiation
      4. Using Reflection
    2. 13. Computation Expressions
      1. Toward Computation Expressions
      2. Computation Expression Builders
      3. Custom Computation Expression Builders
    3. 14. Quotations
      1. Quotation Basics
      2. Generating Quotation Expressions
    4. 15. Type Providers
      1. Typed Data Versus Typed Languages
      2. Type Providers
  6. IV. Appendixes
    1. A. Overview of .NET Libraries
      1. Visualization
      2. Data Processing
      3. Storing Data
    2. B. F# Interop
      1. .NET Interop
      2. Unmanaged Interop
  7. Index
  8. About the Author
  9. Colophon
  10. Copyright

Chapter 10. Scripting

In previous chapters, you saw how F# can be effective across multiple programming paradigms. But F# is not only well suited for different styles of programming, it can also be effective for writing different types of programs as well. F# is not only useful for client applications, but can also be effective as a scripting language too.

Scripting is general term used to describe programs that don’t have a UI and are focused on solving a particular task. In most scripting languages, the script consists entirely of code—as opposed to an executable program—that is then interpreted by a runtime engine.

Programming in this mode typically sacrifices execution speed for the convenience of being able to easily modify and deploy the program. Rather than creating a complex solution designed to work everywhere, you can simply move a script from machine to machine and modify it as necessary.

Although F# may be best suited for client application programming, using it in a scripting context has one major advantage: you already know it. Rather than learning a separate language for your scripts, employing F# for your scripting needs lets you reuse your existing code and knowledge about F# programming. Also, F# code is never interpreted—it is always compiled first. So F# can be comparatively faster than pure scripting languages.

If you have a simple problem and don’t need a complicated interface, consider scripting the solution. In this chapter, you learn about some constructs available ...

The best content for your career. Discover unlimited learning on demand for around $1/day.