Skip to Main Content
Professional F# 2.0
book

Professional F# 2.0

by Ted Neward, Aaron C. Erickson, Talbott Crowell, Richard Minerich
June 2010
Intermediate to advanced content levelIntermediate to advanced
432 pages
10h 44m
English
Wrox
Content preview from Professional F# 2.0

Chapter 14. Immutable Data

WHAT'S IN THIS CHAPTER?

  • Understanding Why Immutability Is Good

  • Managing State and Mutation Responsibly

  • Passing References

  • Enhancing Performance

The term functional is similar to object oriented in that it represents a collection of language design choices and associated design methodologies. In this chapter, you'll explore the data side of functional programming in F# through a combination of language features and methodology. When you arrive on the other side, you'll know why immutable data structures are so important and have ways of handling mutation in a safe way.

THE PROBLEM WITH STATE

For years, the vast majority of programmers have combined data in mutable form and operations on that data in constructs known as classes. Along with the numerous advantages of this methodology come a number of disadvantages that are not often discussed. Most of these disadvantages stem from the use of these classes as black boxes that each encapsulate some part of the state of your program. This state is hidden by a mess of unspecified behavior, implicit in the method definitions of the classes.

When consuming these classes, you find yourself unable to directly understand their implementation. The same call to a class method may produce different results, and often does. This problem is not restricted to a single class because many classes mutate each other or are interlinked with complex networks of events. A single method call can cause a ripple effect of state changes throughout ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Book of F#

The Book of F#

Dave Fancher
Beginning F# 4.0

Beginning F# 4.0

Robert Pickering, Kit Eason

Publisher Resources

ISBN: 9780470528013Purchase book