165人阅读 评论(0)

# Chap 1 Foundations

Introduce notions of value, object, type, procedure and concept that represent different categories of ideas in the computer. A central notion, Regularity enables us to apply equational reasoning (substituting equals for equals) to transform and optimize programs.

## 1.1 Categories of Ideas: Entity, Species, Genus

Abstract Entity: eternal and unchangeable.

E.g Blue and 12.

Concrete Entity: comes into and out of existence in space and time.

E.g  China and Amy.

Attribute: a correspondence between a concrete entity and an abstract entity --- describes some property, measurement or quality of the concrete entity.

E.g the number of China

Identity: a primitive notion of our perception of reality, determines the sameness of a thing changing over time.

Abstract Species: common propertites of equivalent abstract entities.

E.g natural number and color.

Concrete Species: the set of attributes of essentially equivalent concrete entities.

E.g  man and Hubei province.

Function: a rule that associates one or more abstract entities, called arguments from corresponding species with an abstract entity, called the result from another species.

Abstract Genus: different abstract species that are similar in some respect.

E.g  number.

Concrete Genus: different concrete species that are similar.

E.g  mammal

An entity belongs to a single species, and several genera.

## 1.2 Values

A datum is a finite sequence of 0s and 1s.

A value type: a correspondence between a species and a set of datums.

A datum correponding to a particular entity is called a representation of the entity, and the entity is called the interpretation of the datum.

Value: a datum together with its interpretation.

E.g integers are represented in a 32-bit format, and interpreted as integer numerator.

A datum is well formed if and only if that datum represents an abstract entity.

E.g integer is well formed, but float is not.

A value type is properly partial if its values represent a proper subset of the abstract entities in the corresponding species and uniquely represented. otherwise it is total

E.g integer is properly partial, and boolean is total.

A value type is uniquely represented if and only if at most one value corresponds to each abstract entity.

E.g an integer in 2's complement is uniquely represented, but boolean is not.

A value type is ambiguous if and only if a value of the type has more than one interpretation.

E.g true values.

Two values of a value type are equal if and only if they represent the same abstract entity.

They are representational equal if and only if their datums are identical sequences of 0s and 1s.

Lemma 1.1

If a value type is uniquely represented, equality implies representational equality.

Lemma 1.2

If a value type is not ambiguous, representational equality implies equality.

A function defined on a value is regular if and only if it represents equality: substituting an equal value for an argument gives an equal result.

Regular functions allow equational reasoning: substituting equals for equals.

When designing the representation of a value type, 2 tasks: implementing equality and deciding which functions will be regular.

## 1.3 Objects

Memory: a set of words each with an address and a content. The content is obtained by a load operation and changed by a store operation.

An object: a representation of a concrete entity as a value in memory.

It has a state that is a value of some value type and is changeable.It owns a set of resources such as memory words and records in a file to hold its state.

An object type is a pattern for storing and modifying values in memory.

A value type describes states of objects of that type.

Values are unchanging and are independent of any particular implementation in the computer.

Objects are changeable and have computer-specific implementations.

Describing the states of objects in terms of values allows us to abstract from the particular implementations of the objects when discussing equality.

Functional programming deals with values, imperative programming deals with objects.

We use values to represent abstract entities, sequences of values can also represent snapshots of concrete entities.

We use objects to represent concrete entities, and abstract entities: staying constant or taking on different approximations to the abstract.

We use objects because：

1. Objects model changeable concrete entities, such as employee records in a payroll application.

2. Objects provide a powerful way to implement functions on values, such as procedure to calculate square.

3. Computers with memory constitute the only available realization of a universal computational device.

## 1.4 Procedures

A sequence of instructions that modifies the state of some objects, it may also construct or destroy objects.

1. Input/Output consists of objects passed to/from a procedure directly or indirectly through its arguments or returned result.

2. Local State: objects created, destroyed, and usually modified during a single invocation of the procedure.

3. Global State: accessible across many invocations.

4. Own State: accessible only to this procedure but shared across multiple invocations.

A computational basis for a type is a finite set of procedures that enable the construction of any other procedure on the type.

A basis is efficient if and only if any procedure implemented using it is as efficient as an equivalent procedure written in terms of an alternative basis.

A basis is expressive if and only if it allows compact and convenient definitions of procedures on the type.

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：81753次
• 积分：1984
• 等级：
• 排名：千里之外
• 原创：104篇
• 转载：100篇
• 译文：0篇
• 评论：6条
最新评论