wood burning stoves 2.0*
The moose likes Scala and the fly likes Functional Programming in Scala - Table of Contents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Scala
Bookmark "Functional Programming in Scala - Table of Contents" Watch "Functional Programming in Scala - Table of Contents" New topic
Author

Functional Programming in Scala - Table of Contents

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

From the table of contents for the book, what I find is that it looks a lot different to the other commercially available books on Scala. Would you mind elaborating a bit on what content each of the chapters in the book would cover? It need not be so descriptive, but a very high level description of what each of the chapters deliver?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Paul Chiusano
author
Greenhorn

Joined: Feb 06, 2013
Posts: 9
Sure. To start, here's what we say in the preface about the overall structure of the book: (FYI, there is an older version of the preface available here: http://manning.com/bjarnason/FPiS_meap_ch01.pdf, that should be updated soon.)


The book is organized into four parts. In part 1, we proceed from a startling premise--that we restrict ourselves to constructing programs using only _pure_ functions with no _side effects_ such as reading from files or mutating memory. In the first chapter of part 1 we will explain exactly what that means, and give you some idea of the benefits you might reap from that. This idea, of programming with pure functions, leads to a very different way of writing programs than you may be used to. We therefore start from the very beginning, relearning how to write the simplest of programs in a functional way. The chapters in part 1 give an overview of fundamental techniques like how to organize small functional programs, define purely functional data structures, handle errors, and deal with state.

Building on this foundation, part 2 is a series of tutorials on _functional design_. We work through some examples of practical functional libraries, laying bare the thought process that goes into designing them.

While working through the libraries in part 2, it will become clear to you that these libraries follow certain patterns and contain some duplication. This will highlight the need for new and higher abstractions for writing more generalized libraries, and we introduce those abstractions in part 3. These are very powerful tools for reasoning about your code. Once you master them, they hold the promise to make you extraordinarily productive as a programmer.

Part 4 then bridges the remainder of the gap towards writing real-world applications that perform I/O (like working with databases, files, or video displays), and make use of mutable state, all in a purely functional way.

Throughout the book, we rely heavily on programming exercises, carefully sequenced to help you internalize the material. To understand functional programming, it's not enough to learn the theory abstractly. You have to fire up your text editor and write some code. You have to take the theory that you have learned and make it a part of yourself, and of your work.


Going chapter by chapter, here's a bit more detail on part 1:

* Chapter 1 defines FP to mean the absence of side effects, more technically in terms of referential transparency, and shows some of the benefits using a worked example.
* Chapter 2 introduces Scala syntax, and the idea of first-class and higher-order functions.
* Chapter 3 introduces how to define purely functional data structures, using the immutable, singly-linked list as a worked example. We use this opportunity to introduce Scala syntax for what are called algebraic data types, and patterns matching.
* Chapter 4 covers how to do error handling without exceptions. Throwing and catching exceptions is not purely functional.
* Chapter 5 covers laziness, and how it can be used to improve the efficiency and modularity of functional programs.
* Chapter 6 talks about how to handle state in a purely functional way, without actually requiring side effects.

After part 1, we now have the 'vocabulary' needed to start writing functional libraries. Part 2 walks through libraries for defining parallel computations (chapter 7), property-based testing (chapter 8), and parsing (chapter 9). The part 2 chapters have a very different feel than the rest of the book - they are less linear, as we are trying to show the playful, iterative, and creative nature of functional design, and give some insight into how it can proceed. There are lots of exercises, some more open-ended, to try to get readers to try their hand at functional design using the tools developed over the course of part 1. We also introduce lots of related ideas as they come up.

We notice in part 2 that while the domains of these libraries are all very different, very similar structures emerge in the design of each library. Part 3 is devoted to exploring these common structures. By this point in the book, we expect readers will see the need to get rid of the duplication we've seen in writing various functional libraries in parts 1 and 2. We cover a few common structures, monoids (chapter 10), monads (chapter 11), and applicative functors (chapter 12), which eliminate duplication seen in parts 1 and 2, and also try to give some idea of how to spot these more abstract structures in day to day programming.

Finally, in part 4, we turn our attention to interacting with the real world, building on the material in parts 1-3. Chapters 13 builds up to an IO type supporting nonblocking I/O, introduces some related ideas (the 'free' monad), and shows how to 'embed' imperative programs into functional programs, giving us first-class imperative programs that can be combined and abstracted using the usual tools of FP. Chapter 14 is a bit more philosophical - it explores more carefully what it means to be free of side effects, discusses 'observability' of side effects, and introduces the idea that _local_ effects do not break functional purity / referential transparency. It also demonstrates how we can restrict the scope of the side effect of mutation using the type system.

Finally, chapter 15 builds up a more compositional library for doing IO, which lets us more cleanly separate the logic of our program from the I/O.

Our goal is that by the end, you'll have all the tools you need to start writing pure functional programs, for just about any programming task you can think of. This is not to say that you'll know everything there is to know about FP, but we expect you'll have all the tools and background to quickly learn whatever comes up in your day to day work with FP.

Hope this helps.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

That was pretty much detailed that I was expecting. Thank you very much for that!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Functional Programming in Scala - Table of Contents