Skip to content

Commit

Permalink
Add all cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansOlsson committed Sep 9, 2022
1 parent 421ffc6 commit 4d2df99
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions chapters/interface.tex
Expand Up @@ -602,25 +602,29 @@ \section{Type Compatible Expressions}\label{type-compatible-expressions}
In an expression that is not an array expression those elements must be type compatible.
In an array expression the two records may contain elements with different sizes, but apart from that they must be type compatible.
That generates a heterogenous array of records, see \cref{arrays}.
The type of the full expression is a record comprised of named elements that are compatible with the corresponding named elements of both \lstinline!A! and \lstinline!B!.
\item
If \lstinline!A! is an array expression then \lstinline!B! must also be an array expression, and \lstinline!ndims(A)! = \lstinline!ndims(B)!.
The type of the full expression is a record comprised of named elements that are type compatible with the corresponding named elements of both \lstinline!A! and \lstinline!B!.
\item The rules for array expressions depend on the operation (the rules for binary operators are given in \cref{scalar-vector-matrix-and-array-operator-functions}
and for array concatenation in \cref{array-concatenation}).
The rules for the remaining case of \lstinline!if!-expressions and array-expressions are:
\begin{itemize}
\item If \lstinline!A! is an array expression then \lstinline!B! must also be an array expression, and \lstinline!ndims(A)! = \lstinline!ndims(B)!.
The type of the full expression is an array expression with elements compatible with the elements of both \lstinline!A! and \lstinline!B!.
If both \lstinline!size(A)! and \lstinline!size(B)! are known and \lstinline!size(A)! = \lstinline!size(B)! then this defines the size of the full expression, otherwise the size of the full expression is not known until the expression is about to be evaluated.
In case of an \lstinline!if!-expression the size of the full expression is defined based on the branch selected, and for other cases \lstinline!size(A)! = \lstinline!size(B)! must hold at this point.
\item
If \lstinline!A! is a scalar expression of a simple type \lstinline!B! must also be a scalar expression of a simple type.
\item
If \lstinline!A! is a \lstinline!Real! expression then \lstinline!B! must be a \lstinline!Real! or \lstinline!Integer! expression and the type of the full expression is \lstinline!Real!, compare \cref{standard-type-coercion}.
\item If \lstinline!A! is a scalar expression of a simple type \lstinline!B! must also be a scalar expression of a simple type.
\end{itemize}
\item If \lstinline!A! is a \lstinline!Real! expression then \lstinline!B! must be a \lstinline!Real! or \lstinline!Integer! expression.
The type of the full expression is \lstinline!Real!, compare \cref{standard-type-coercion}, unless the operator is a relational operator \cref{equality-relational-and-logical-operators} where the type of the full expression is \lstinline!Boolean!.
\item
If \lstinline!A! is an \lstinline!Integer! expression then \lstinline!B! must be a \lstinline!Real! or \lstinline!Integer! expression.
For exponentiation and division the type of the full expression is \lstinline!Real! (even if both \lstinline!A! and \lstinline!B! are \lstinline!Integer!) see \cref{element-wise-exponentiation} and \cref{division-by-numeric-scalars}, in other cases the type of the full expression is \lstinline!Real! or \lstinline!Integer! (same as \lstinline!B!), compare \cref{standard-type-coercion}.
For exponentiation and division the type of the full expression is \lstinline!Real! (even if both \lstinline!A! and \lstinline!B! are \lstinline!Integer!) see \cref{element-wise-exponentiation} and \cref{division-by-numeric-scalars}, for relational operators the type of the full expression is \lstinline!Boolean!.
In other cases the type of the full expression is \lstinline!Real! or \lstinline!Integer! (same as \lstinline!B!), compare \cref{standard-type-coercion}.
\item
If \lstinline!A! is a \lstinline!Boolean! expression then \lstinline!B! must be a \lstinline!Boolean! expression and the type of the full expression is \lstinline!Boolean!.
If \lstinline!A! is a \lstinline!Boolean! expression then \lstinline!B! must be a \lstinline!Boolean! expression and the type of the full expression is \lstinline!Boolean!.
\item
If \lstinline!A! is a \lstinline!String! expression then \lstinline!B! must be a \lstinline!String! expression and the type of the full expression is \lstinline!String!.
If \lstinline!A! is a \lstinline!String! expression then \lstinline!B! must be a \lstinline!String! expression and the type of the full expression is \lstinline!String!, unless the operator is a relational operator \cref{equality-relational-and-logical-operators} where the type of the full expression is \lstinline!Boolean!.
\item
If \lstinline!A! is an enumeration expression then \lstinline!B! must be an enumeration expression and the type of the full expression is enumeration expression.
If \lstinline!A! is an enumeration expression then \lstinline!B! must be an enumeration expression and the type of the full expression is enumeration expression, unless the operator is a relational operator \cref{equality-relational-and-logical-operators} where the type of the full expression is \lstinline!Boolean!.
The enumeration expressions must be defined in terms of an enumeration type with the same enumeration literals in the same order.
\item
For array and \lstinline!if!-expressions, if \lstinline!A! has an \lstinline!operator record! base class then \lstinline!B! must also have an \lstinline!operator record! base class, and it must be the same, and otherwise neither \lstinline!A! nor \lstinline!B! may have an \lstinline!operator record! base class.
Expand Down

0 comments on commit 4d2df99

Please sign in to comment.