Unix System Programming with Standard ML

Version: 0.1, Mar 2002

Permission is granted for you to make copies of this version of this book for educational purposes but the copies may not be sold or otherwise used for direct commercial advantage. This permission is granted provided that this copyright and permission notice is preserved on all copies. All other rights are reserved.

While every precaution has been taken in the preparation of this book, the author assumes no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.


Table of Contents
Preface
The Audience
The Environment
I. Programming with Standard ML
1. Introduction
What is Functional Programming?
2. Hello World
Assembling the Hello World Program
The echo Program
Loops and Recursion
The getopt Programs
3. The Basis Library
Preliminaries
General
Option
Bool
Text
Integers
Reals
Lists
Arrays and Vectors
The Portable I/O API
The Portable OS API
The POSIX API
4. The SML/NJ Extensions
The Unsafe API
Signals
The SMLofNJ API
The Socket API
5. The Utility Libraries
Data Structures
Algorithms
Regular Expressions
Other Utilities
6. Concurrency
Continuations
Coroutines
The CML Model
A Counter Object
Some Tips on Using CML
Getting the Counter's Value
Getting the Value through an Event
Getting the Value with a Time-Out
More on Time-Outs
Semaphores
Semaphores via Synchronous Variables
7. Under the Hood
Memory Management
Performance
II. The Project
8. The Swerve Web Server
Introduction
The HTTP Protocol
The Resource Store
Server Configuration
The Architecture of the Server
Building and Testing the Server
9. The Swerve Detailed Design
Introduction
The Organisation of the Code
The Main Layer
The Server Layer
The Store Layer
The IETF Layer
The Config Layer
The Common Layer
10. Conclusion
SML/NJ vs Real-World Needs
Large-scale Development
Performance
Infrastructure
Related Languages
To Finish
A. Learning SML
Books
Tutorials
B. Coping with the Compiler's Error Messages
Syntax Errors
Identifier Errors
Record Errors
Type Errors
Simple Type Errors
If and Case Expressions
Non-local Type Errors
C. Installation
Bibliography
Glossary
List of Tables
5-1. Format flags.
5-2. Format types.
7-1. The Low-Order Bits of a Record Field.
7-2. Speed of the Counting Functions.
7-3. Speed of the Line Counting Functions.
7-4. Speed of Linked List Building.
8-1. The Notable Norm URLs.
8-2. Sequential Server Performance
8-3. Concurrent Swerve Performance
8-4. Concurrent Apache Performance
8-5. Timing Measurement Points.
9-1. The Module Layers of the Server.
List of Figures
1-1. A Classification of Some Languages
1-2. The expression (x + y) * (u + v)
2-1. Compiling and Running a Program
2-2. Summing a list by Divide and Conquer.
2-3. Tail Recursion as Data Flow
2-4. Tail Recursion as Iteration
2-5. The Data Flow for foldl
2-6. Counting Words with a FSM
3-1. Some Stream Transformations
3-2. The Major Signatures of the Portable I/O API
3-3. The Major Structures Implementing the Portable I/O API
5-1. Updating a Tree.
5-2. A Fifo as a Pair of Lists.
6-1. A Simple Flow Chart
6-2. Two Coroutines
6-3. A CML Thread
6-4. A Network of Events
6-5. Getting the Counter's Value
6-6. Getting the Value with a Time-Out
6-7. The Timing of Semaphore Test 2
7-1. Steps in Copying Collection.
7-2. The Layout of a Record.
8-1. A URL navigating the Resource Store.
8-2. The Functional Blocks of the Server.
8-3. Entities, Producers and Consumers.
8-4. The Producer-Consumer Transfer Protocol.
8-5. A Resource Store Node.
8-6. Connection-CGI Collaboration.
9-1. The Main Dependencies of the Upper Layers.
9-2. The Open Manager Objects.
9-3. The File Opening Handshake.