Commit 03628a23 by Pietro Abate

### [r2003-05-21 19:14:36 by cvscast] Manual

```Original author: cvscast
Date: 2003-05-21 19:14:36+00:00```
parent 4c388a8e
 ... @@ -26,7 +26,7 @@ or as a pair pattern of two type constraints. ... @@ -26,7 +26,7 @@ or as a pair pattern of two type constraints.

In this page, we present all the types and patterns that CDuce recognize. In this page, we present all the types and patterns that CDuce recognizes. It is also the occasion to present the CDuce values themselves, the It is also the occasion to present the CDuce values themselves, the corresponding expression constructions, and fundamental operations on them. corresponding expression constructions, and fundamental operations on them.

... @@ -35,7 +35,8 @@ corresponding expression constructions, and fundamental operations on them. ... @@ -35,7 +35,8 @@ corresponding expression constructions, and fundamental operations on them.

CDuce recognize the full set of boolean connectives. CDuce recognize the full set of boolean connectives, whose interpretation is purely set-theoretic.

• Empty denotes the empty type (no value).
• Empty denotes the empty type (no value).
• ... @@ -83,11 +84,18 @@ works for recursive patterns (for which there is no toplevel declarations). ... @@ -83,11 +84,18 @@ works for recursive patterns (for which there is no toplevel declarations).

There is an important restriction concerning recursive types: There is an important restriction concerning recursive types: any cycle must cross any cycle must cross a type constructor (pairs, records, XML elements, arrows). Boolean connectives do not count as type constructors ! The code sample above is a correct definition. The one below is invalid, because there is an unguarded cycle between T and S.

... @@ -191,7 +199,7 @@ Tuples are syntactic sugar for pairs. For instance, ... @@ -191,7 +199,7 @@ Tuples are syntactic sugar for pairs. For instance,

Sequences are fundamental in CDuce. They represents Sequences are fundamental in CDuce. They represents ... @@ -210,6 +218,8 @@ E.g.: [ 1 2 3 4 ]. ... @@ -210,6 +218,8 @@ E.g.: [ 1 2 3 4 ].

The binary operator @ denotes sequence concatenation. The binary operator @ denotes sequence concatenation. E.g.: [ 1 2 3 ] @ [ 4 5 6 ] evaluates to [ 1 2 3 4 5 6 ].

... @@ -286,6 +296,77 @@ in a pattern, e.g.: [ x::Int* ; _ ]. ... @@ -286,6 +296,77 @@ in a pattern, e.g.: [ x::Int* ; _ ].

In CDuce, character strings are nothing but sequences of characters. The type String is pre-defined as [ Char* ]. This allows to use the full power of regular expression pattern matching with strings.

Inside a regular expression type or pattern, it is possible to use PCDATA instead of Char* (note that both are not types on their own, they only make sense inside square brackets, contrary to String).

Records are set of finite (name,value) bindings. They are used in particular to represent XML attribute sets.

The syntax of a record expression is { %%l1%% = %%e1%%; %%...%%; %%ln%% = %%en%% } where the %%li%% are label names (same lexical conventions as for identifiers), and the %%vi%% are expressions.

They are two kinds of record types. Open record types are written { %%l1%% = %%t1%%; %%...%%; %%ln%% = %%tn%% }, and closed record types are written { %%l1%% = %%t1%%; %%...%%; %%ln%% = %%tn%% }. Both denote all the record values where the labels %%li%% are present and the associated values are in the corresponding type. The distinction is that that open type allow extra fields, whereas the closed type gives a strict enumeration of the possible fields.

Additionally, both for open and close record types, it is possible to specify optional fields by using =? instead of = between a label and a type. For instance, {| x = Int; y =? Bool |} represents records with an x field of type Int, an optional field y (when it is present, it has type Bool), and no other field.

Note that the value { x = 1; y = 2 } has actually the type {| x = 1; y = 2 |} which is more precise than { x = 1; y = 2 }. This is the only situation where the singleton type corresponding to a constructed value is not syntactically equal to this value.

The syntax is the same for patterns. Note that capture variables cannot appear in an optional field.

... @@ -317,6 +398,62 @@ can be written: ... @@ -317,6 +398,62 @@ can be written: <a href=String>[]. <a href=String>[].

The following sample shows several way to write XML types.

[ A* ];; type B = <(`x | `y)>[ ];; type C = [ ];; type U = { x = String; y =? String };; type V = [ W* ];; type W = V;; ]]>

CDuce is an higher-order functional languages: functions are first-class citizen values, and can be passed as argument or returned as result, stored in data structure, etc...

A functional type has the form %%t%% -> %%s%% where %%t%% and %%s%% are types. Intuitively, this type corresponds to functions that accept (at least) any argument of type %%t%%, and for such an argument, returns a value of type %%s%%. For instance, the type (Int,Int) -> Int & (Char,Char) -> Char denotes functions that maps any pair of integer to an integer, and any pair of characters to a character.

The explanation above gives the intuition behind the interpretation of functional types. It is sufficient to understand which subtyping relations and equivalences hold between (boolean combination) of functional types. For instance, Int -> Int & Char -> Char is a subtype of (Int|Char) -> (Int|Char) because with the intuition above, a function of the first type, when given a value of type Int|Char returns a value of type Int or of type Char (depending on the argument).

Formally, the type %%t%% -> %%s%% denotes CDuce abstractions fun (%%t1%% -> %%s1%%; %%...%%; %%tn%% -> %%sn%%)... such that %%t1%% -> %%s1%% & %%...%% & %%tn%% -> %%sn%% is a subtype of %%t%% -> %%s%%.

... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!