Clean Clean Clean Clean Clean

Version 3.0
Language Report

Table of Contents

Preface

Chapter 1 Basic Semantics

1.1Graph Rewriting
    1.1.1A Small Example
1.2Global Graphs

Chapter 2 Modules and Scopes

2.1Identifiers, Scopes and Name Spaces
    2.1.1Naming Conventions of Identifiers
    2.1.2Scopes and Name Spaces
    2.1.3Nesting of Scopes
2.2Modular Structure of Clean Programs
2.3Implementation Modules
    2.3.1The Main or Start Module
    2.3.2Scope of Global Definitions in Implementation Modules
    2.3.3Begin and End of a Definition: the Layout Rule
2.4Definition Modules
2.5Importing Definitions
    2.5.1Explicit Imports of Definitions
    2.5.2Implicit Imports of Definitions
2.6System Definition and Implementation Modules

Chapter 3 Defining Functions and Constants

3.1Functions
3.2Patterns
3.3Guards
3.4Expressions
    3.4.1Lambda Abstraction
    3.4.2Case Expression and Conditional Expression
    3.4.3Matches Pattern Expression
3.5Local Definitions
    3.5.1Let Expression: Local Definitions in Expressions
    3.5.2Where Block: Local Definitions in a Function Alternative
    3.5.3With Block: Local Definitions in a Guarded Alternative
    3.5.4Let-Before Expression: Local Constants defined between Guards
3.6Defining Constants
    3.6.1Selectors
3.7Typing Functions
    3.7.1Typing Curried Functions
    3.7.2Typing Operators
    3.7.3Typing Partial Functions
    3.7.4Explicit use of the Universal Quantifier in Function Types
    3.7.5Functions with Strict Arguments

Chapter 4 Predefined Types

4.1Basic Types: Int, Real, Char and Bool
    4.1.1Creating Constant Values of Basic Type
    4.1.2Patterns of Basic Type
4.2Lists
    4.2.1Creating Lists
    4.2.2List Patterns
4.3Tuples
    4.3.1Creating Tuples
    4.3.2Tuple Patterns
4.4Arrays
    4.4.1Creating Arrays and Selection of field Elements
    4.4.2Array Patterns
4.5Predefined Type Constructors
4.6Arrow Types
4.7Predefined Abstract And Synonym Types
4.8Predefined Unit Type

Chapter 5 Defining New Types

5.1Defining Algebraic Data Types
    5.1.1Using Constructors in Patterns
    5.1.2Using Higher Order Types
    5.1.3Defining Algebraic Data Types with Existentially Quantified Variables
    5.1.4Defining Algebraic Data Types with Universally Quantified Variables
    5.1.5Extensible Algebraic Types
    5.1.6Strictness Annotations in Type Definitions
    5.1.7Semantic Restrictions on Algebraic Data Types
5.2Defining Record Types
    5.2.1Creating Records and Selection of Record Fields
    5.2.2Record Patterns
5.3Defining Synonym Types
5.4Defining Abstract Data Types
    5.4.1Defining Abstract Data Types with Synonym Type Definition

Chapter 6 Overloading

6.1Type Classes
6.2Functions Defined in Terms of Overloaded Functions
6.3Type Classes Defined in Terms of Overloaded Functions
6.4Type Constructor Classes
6.5Overlapping Instances
6.6Internal Overloading
6.7Defining Derived Members in a Class
6.8A Shorthand for Defining Overloaded Functions
6.9Classes Defined in Terms of Other Classes
6.10Exporting Type Classes
6.11Semantic Restrictions on Type Classes

Chapter 7 Generic Programming

7.1Basic Ideas Behind Generic Programming
7.2Defining Generic Functions
7.3Deriving Generic Functions
7.4Applying Generic Functions
7.5Using Constructor Information
7.6Generic Functions and Uniqueness Typing
7.7Generic Functions Using Other Generic Functions
7.8Exporting Generic Functions

Chapter 8 Dynamics

8.1Packing Expressions into a Dynamic
    8.1.1Packing Abstract Data Types
    8.1.2Packing Overloaded Functions
    8.1.3Packing Expressions of Unique Type
    8.1.4Packing Arguments of Unknown Type
    8.1.5Using Dynamic Typing to Defeat the Static Type System
8.2Unpacking Dynamics Using a Dynamic Pattern Match
    8.2.1Unpacking Abstract Data Types
    8.2.2Unpacking of Overloaded Functions
    8.2.3Unpacking Expressions of Unique Type
    8.2.4Checking and Unifying Types Schemes using Type Pattern Variables
    8.2.5Checking and Unifying Unknown Types using Overloaded Type Variables
8.3Type Safe Communication using Dynamics
8.4Architecture of the implementation
8.5Semantic Restrictions on Dynamics

Chapter 9 Uniqueness Typing

9.1Basic Ideas behind Uniqueness Typing
9.2Attribute Propagation
9.3Defining New Types with Uniqueness Attributes
9.4Uniqueness and Sharing
    9.4.1Higher Order Uniqueness Typing
    9.4.2Uniqueness Type Coercions
9.5Combining Uniqueness Typing and Overloading
    9.5.1Constructor Classes
9.6Higher-Order Type Definitions
9.7Destructive Updates using Uniqueness Typing

Chapter 10 Strictness, Macros and Efficiency

10.1Annotations to Change Lazy Evaluation into Strict Evaluation
    10.1.1Advantages and Disadvantages of Lazy versus Strict Evaluation
    10.1.2Strict and Lazy Context
    10.1.3Space Consumption in Strict and Lazy Context
    10.1.4Time Consumption in Strict and Lazy Context
    10.1.5Changing Lazy into Strict Evaluation
10.2Defining Graphs on the Global Level
10.3Defining Macros
10.4Efficiency Tips

Chapter 11 Foreign Language Interface

11.1Foreign Export
11.2Using ABC instructions

Appendix A Context-Free Syntax Description

A.1Clean Program
A.2Import Definition
A.3Function Definition
    A.3.1Types of Functions
    A.3.2Patterns
    A.3.3Graph Expressions
A.4Macro Definition
A.5Type Definition
    A.5.1Types Expression
A.6Class and Instance Definitions
A.7Generic Definitions
A.8Foreign Export Definition
A.9Names

Appendix B Lexical Structure

B.1Lexical Program Structure
B.2Comments
B.3Identifiers
B.4Denotations
B.5Reserved Keywords and Symbols

Appendix C Bibliography

Appendix D Compiler Extensions

D.1Clean 3.0 Compiler Extensions
    D.1.1New imports
    D.1.2Uniqueness typing additions
    D.1.3Hierarchical modules
D.2Clean Development Compiler Extensions
D.3Clean ITask Compiler Extensions