Mercurial > hg > ishara
changeset 35:f1ce7876346a
Updated docs.
author | samer |
---|---|
date | Mon, 21 Jan 2013 11:01:45 +0000 |
parents | c75bb62b90a9 |
children | 9e7be347b3a0 |
files | README.txt |
diffstat | 1 files changed, 25 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/README.txt Sun Jan 20 19:05:05 2013 +0000 +++ b/README.txt Mon Jan 21 11:01:45 2013 +0000 @@ -76,7 +76,7 @@ The array domain D is written as the literal array that would be returned as the size of the array, eg [N,N] for a square N-by-N array, or [N] for an N-by-1 array. - Hence the types of these arrays could be [[N,N]] and [[N]->integer] respectively. + Hence [[N,N]] and [[N]->integer] are valid array types. Higher dimensional array types are written analogously: [[N,M,L]], etc.. @@ -87,6 +87,15 @@ <type_list> ::= <type_spec> [, <type_list>] + Note, functions typed as A->B are expected to be purely functional and referentially + transparent: the return values must depend only the inputs and not on any global state, + global state must not be affected, and there may be no side effects including IO. In + practice, the odd status message is fine. Functions that use global state, do IO, make + noises, draw graphics etc should use A=>B. In particular functions with no return values + *must* have side effects if there is to be any point in calling them, so (A->void) is + a useless type and should never appear. Similarly, a function with type (void->A) must + always return the same value. + Cells and tuples cells(A) - arbitrary length row array of cells (list) of type A, equivalent to {[1,N]->A} @@ -190,6 +199,8 @@ We then let void denote Z{:}, that is, an empty comma separated list. This means that void now truly denotes 0 types, not one degenerate type. + Array domain types + The comma-separated lists idea can also be used to account for the types of multidimensional arrays, which are rather like functions from one or more integers to the array element type; in Matlab, the array reference x(i,j,k) @@ -239,6 +250,19 @@ where the meta-type size(E) denotes the set of types that look like [N,M,...], ie that look like arrays of the type [[1,E]->natural]. + Note that a cell array is just an ordinary array whose elements are cells, + so the following types are equivalent: + + [Dom->box(R)] == [Dom->cell {R}] == {Dom->R} + + As a final example of the sort of thing that can be expressed using this type + system, the following are all equivalent (assuming A is a cell array of N types, + ie A@typelist(N) or A@{[N]->type}: + + [I:[N]->box(A{I})] == {I:[N]->A{I}} == cell A(1:N) == cell {A{1:N}} + + So that clears that up then. + User-defined types Further types can be defined either as type synonyms written as A ::= B, where