Functional Programming
1. Table of Contents
0
Table of Contents
7.2
Mutable Pairs and Non-list Structures
1
Table of Contents
7.3
Promises and Delay/Force Revisited
2
Programming Styles
8
Tail Recursion
2.1
Introduction
8.1
What is tail recursion?
2.2
Syntax and Semantics
8.2
Converting to tail-recursive form
2.3
Operational Semantics
8.3
Converting tail-recursion to loop form
2.4
Transformational Semantics
9
Continuations
2.5
Programming Styles
9.1
What is a continuation?
3
A Simple Subset of Scheme
9.2
Simple Recursion: The Factorial Example
3.1
Scheme
9.3
Complex Recursion: Tree Traversal with Continuations
3.2
Restricted Scheme
10
Continuations continued
3.3
Some Illustrative Examples
10.1
call/cc and support for Continuations
3.4
Scheme Naming Conventions
10.2
Breaking and Resuming
3.5
Iterated Function Composition
10.3
Tree Traversal With Error Bailout
4
Techniques for Functional Programming
10.4
Co-routines
4.1
Abstract, Map, Fold/Reduce, Recurse!
10.5
Exceptions With Continuations
4.2
Compute Once, Reuse Many
10.6
Unexpected Behaviour
4.3
Use
cond
instead of
if
for guarded commands
10.7
Simple Threads
4.4
Pass State Down the Recursion
11
Haskell Intro
4.5
Use Local Functions to Avoid Passing Common Data
11.1
The Haskell functional programming language
4.6
Restructure Your Code for Clarity
11.2
Haskell References
4.7
Use an Accumulator to Pass Partial Results Down
11.3
Obtaining the Haskell environment
4.8
Use Default Parameters to Start the Computation
11.4
Preliminaries
4.9
Getting the tail back in recursion
11.5
Operators
4.10
Prefix Computation
11.6
More ...
5
Definition and Evaluation
11.7
Terminology and Notions
5.1
Evaluation Strategies
12
Types
5.2
Special Forms Are Lazy
12.1
Expression Trees
5.3
Implementing Conditional Special Forms With Functional Truth
12.2
Type Classes
5.4
Implementing Lazy Evaluation
13
Haskell Examples - Simple Parsing
5.5
Diversion - Objects Are Just Closures
13.1
Building up a simple parser for numbers
6
Streams
13.2
Making the parsing process abstract
6.1
Streams - How To Handle Infinite Objects
13.3
Evaluation as parsing
6.2
Examples Of Stream Operations
13.4
Cleaning Up the Parser
6.3
The Stream of Primes
13.5
Typeclasses and Handling Errors
6.4
Implicit Streams and Fixed Points
14
Haskell Tips
6.5
The Square Root Stream
14.1
Conversion
6.6
The Pi Stream
14.2
Modules
6.7
Another Stream Implementation Variant
15
Revision Log
7
Mutable State
16
End of Document
7.1
Capturing Mutable State In Closures
1. Table of Contents
Notes on Functional Programming / Version 2.10 2014-02-24