OLD | NEW |
1 \documentclass{article} | 1 \documentclass{article} |
2 \usepackage{epsfig} | 2 \usepackage{epsfig} |
3 \usepackage{dart} | 3 \usepackage{dart} |
4 \usepackage{bnf} | 4 \usepackage{bnf} |
5 \usepackage{hyperref} | 5 \usepackage{hyperref} |
6 \newcommand{\code}[1]{{\sf #1}} | 6 \newcommand{\code}[1]{{\sf #1}} |
7 \title{Dart Programming Language Specification \\ | 7 \title{Dart Programming Language Specification \\ |
8 {\large Draft Version 0.61}} | 8 {\large Draft Version 0.61}} |
9 \author{The Dart Team} | 9 \author{The Dart Team} |
10 \begin{document} | 10 \begin{document} |
(...skipping 4334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4345 } | 4345 } |
4346 %does not denote a type available in the current lexical scope. It is a %compile
-time error % CHANGED | 4346 %does not denote a type available in the current lexical scope. It is a %compile
-time error % CHANGED |
4347 %run-time error | 4347 %run-time error |
4348 %if $T$ is a parameterized type of the form $G<T_1, \ldots, T_n>$ and $G$ is not
a generic type with $n$ type parameters. | 4348 %if $T$ is a parameterized type of the form $G<T_1, \ldots, T_n>$ and $G$ is not
a generic type with $n$ type parameters. |
4349 | 4349 |
4350 %Note, that, in checked mode, it is a dynamic type error if a malformed type is
used in a type test as specified in \ref{dynamicTypeSystem}. | 4350 %Note, that, in checked mode, it is a dynamic type error if a malformed type is
used in a type test as specified in \ref{dynamicTypeSystem}. |
4351 | 4351 |
4352 %It is a static warning if $T$ is malformed or malbounded. | 4352 %It is a static warning if $T$ is malformed or malbounded. |
4353 %does not denote a type available in the current lexical scope. | 4353 %does not denote a type available in the current lexical scope. |
4354 | 4354 |
4355 Let $v$ be a local variable or a formal parameter. An is-expression of the form
\code{$v$ \IS{}! $T$} shows that $v$ has type $T$ iff $T$ is a subtype of the
type $S$ of the expression $v$ and both $T \ne \DYNAMIC{}$ and $S \ne \DYNAMIC{
}$. | 4355 Let $v$ be a local variable or a formal parameter. An is-expression of the form
\code{$v$ \IS{}! $T$} shows that $v$ has type $T$ iff $T$ is more specific tha
n the type $S$ of the expression $v$ and both $T \ne \DYNAMIC{}$ and $S \ne \DY
NAMIC{}$. |
4356 | 4356 |
4357 The static type of an is-expression is \code{bool}. | 4357 The static type of an is-expression is \code{bool}. |
4358 %It is a static warning if if $T$ is a parameterized type of the form $G<T_1, \l
dots, T_n>$ and $G$ is not a generic type with $n$ type parameters. | 4358 %It is a static warning if if $T$ is a parameterized type of the form $G<T_1, \l
dots, T_n>$ and $G$ is not a generic type with $n$ type parameters. |
4359 | 4359 |
4360 | 4360 |
4361 | 4361 |
4362 \subsection{ Type Cast} | 4362 \subsection{ Type Cast} |
4363 \label{typeCast} | 4363 \label{typeCast} |
4364 | 4364 |
4365 The {\em cast expression} ensures that an object is a member of a type. | 4365 The {\em cast expression} ensures that an object is a member of a type. |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5698 A type $T$ is more specific than a type $S$, written $T << S$, if one of the fo
llowing conditions is met: | 5698 A type $T$ is more specific than a type $S$, written $T << S$, if one of the fo
llowing conditions is met: |
5699 \begin{itemize} | 5699 \begin{itemize} |
5700 \item $T$ is $S$. | 5700 \item $T$ is $S$. |
5701 \item T is $\bot$. | 5701 \item T is $\bot$. |
5702 \item S is \DYNAMIC{}. | 5702 \item S is \DYNAMIC{}. |
5703 \item $S$ is a direct supertype of $T$. | 5703 \item $S$ is a direct supertype of $T$. |
5704 \item $T$ is a type parameter and $S$ is the upper bound of $T$. | 5704 \item $T$ is a type parameter and $S$ is the upper bound of $T$. |
5705 \item $T$ is a type parameter and $S$ is \cd{Object}. | 5705 \item $T$ is a type parameter and $S$ is \cd{Object}. |
5706 \item $T$ is of the form $I<T_1, \ldots, T_n>$ and $S$ is of the form $I<S_1, \l
dots, S_n>$ and: | 5706 \item $T$ is of the form $I<T_1, \ldots, T_n>$ and $S$ is of the form $I<S_1, \l
dots, S_n>$ and: |
5707 $T_i << S_i, 1 \le i \le n$ | 5707 $T_i << S_i, 1 \le i \le n$ |
| 5708 \item $T$ and $S$ are both function types, and $T << S$ under the rules of secti
on \ref{functionTypes}. |
5708 \item $T << U$ and $U << S$. | 5709 \item $T << U$ and $U << S$. |
5709 \end{itemize} | 5710 \end{itemize} |
5710 | 5711 |
5711 $<<$ is a partial order on types. | 5712 $<<$ is a partial order on types. |
5712 $T$ is a subtype of $S$, written $T <: S$, iff $[\bot/\DYNAMIC{}]T << S$. | 5713 $T$ is a subtype of $S$, written $T <: S$, iff $[\bot/\DYNAMIC{}]T << S$. |
5713 | 5714 |
5714 \rationale{ | 5715 \rationale{ |
5715 Note that $<:$ is not a partial order on types, it is only binary relation on ty
pes. This is because $<:$ is not transitive. If it was, the subtype rule would h
ave a cycle. For example: | 5716 Note that $<:$ is not a partial order on types, it is only binary relation on ty
pes. This is because $<:$ is not transitive. If it was, the subtype rule would h
ave a cycle. For example: |
5716 $List <: List<String>$ and $List<int> <: List$, but $List<int>$ is not a subtype
of $List<String>$. | 5717 $List <: List<String>$ and $List<int> <: List$, but $List<int>$ is not a subtype
of $List<String>$. |
5717 Although $<:$ is not a partial order on types, it does contain a partial order,
namely $<<$. This means that, barring raw types, intuition about classical subty
pe rules does apply. | 5718 Although $<:$ is not a partial order on types, it does contain a partial order,
namely $<<$. This means that, barring raw types, intuition about classical subty
pe rules does apply. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5804 | 5805 |
5805 % ensure that Object and dynamic may be assign dot a function type | 5806 % ensure that Object and dynamic may be assign dot a function type |
5806 A function is always an instance of some class that implements the class \code{F
unction} and implements a \CALL{} method with the same signature as the function
. All function types are subtypes of \code{Function}. | 5807 A function is always an instance of some class that implements the class \code{F
unction} and implements a \CALL{} method with the same signature as the function
. All function types are subtypes of \code{Function}. |
5807 If a type $I$ includes an instance method named \CALL{}, and the type of \CALL{}
is the function type $F$, then $I$ is considered to be a subtype of $F$. It is
a static warning if a concrete class implements \cd{Function} and does not have
a concrete method named \CALL{}. | 5808 If a type $I$ includes an instance method named \CALL{}, and the type of \CALL{}
is the function type $F$, then $I$ is considered to be a subtype of $F$. It is
a static warning if a concrete class implements \cd{Function} and does not have
a concrete method named \CALL{}. |
5808 | 5809 |
5809 | 5810 |
5810 | 5811 |
5811 | 5812 |
5812 %\commentary{Need to specify how a function values dynamic type is derived from
its static signature.} | 5813 %\commentary{Need to specify how a function values dynamic type is derived from
its static signature.} |
5813 | 5814 |
| 5815 A function type $(T_1, \ldots T_{k}, [T_{k+1} \ldots, T_{n+m}]) \rightarrow T$
is a more specific than the |
| 5816 function type $(S_1, \ldots, S_{k+j}, [S_{k+j+1} \ldots, S_{n}]) \rightarrow S$,
if all of the following conditions are met: |
| 5817 \begin{enumerate} |
| 5818 \item Either |
| 5819 \begin{itemize} |
| 5820 \item $S$ is \VOID{}, Or |
| 5821 \item $T << S$. |
| 5822 \end{itemize} |
| 5823 \item $\forall i \in 1 .. n, T_i << S_i$. |
| 5824 \end{enumerate} |
| 5825 |
| 5826 |
| 5827 A function type $(T_1, \ldots T_n, \{T_{x_1}$ $x_1, \ldots, T_{x_k}$ $x_k\}) \ri
ghtarrow T$ is more specific than the function type $(S_1, \ldots, S_n, \{S_{y_1
}$ $y_1, \ldots, S_{y_m}$ $y_m\}) \rightarrow S$, if all of the following condit
ions are met: |
| 5828 \begin{enumerate} |
| 5829 \item Either |
| 5830 \begin{itemize} |
| 5831 \item $S$ is \VOID{}, Or |
| 5832 \item $T << S$. |
| 5833 \end{itemize} |
| 5834 \item $\forall i \in 1 .. n, T_i << S_i$. |
| 5835 \item $k \ge m$ and $y_i \in \{x_1, \ldots, x_k\}, i \in 1 .. m$. |
| 5836 %\{x_1, \ldots, x_k\}$ is a superset of $\{y_1, \ldots, y_m\}$. |
| 5837 \item For all $y_i \in \{y_1, \ldots, y_m\}, y_i = x_j \Rightarrow T_j << S_i$ |
| 5838 \end{enumerate} |
| 5839 |
| 5840 Furthermore, if $F$ is a function type, $F << \code{Function}$. |
| 5841 |
| 5842 |
5814 \subsection{Type \DYNAMIC{}} | 5843 \subsection{Type \DYNAMIC{}} |
5815 \label{typeDynamic} | 5844 \label{typeDynamic} |
5816 | 5845 |
5817 The type \DYNAMIC{} denotes the unknown type. | 5846 The type \DYNAMIC{} denotes the unknown type. |
5818 | 5847 |
5819 If no static type annotation has been provided the type system assumes the decla
ration has the unknown type. If a generic type is used but type arguments are no
t provided, then the type arguments default to the unknown type. | 5848 If no static type annotation has been provided the type system assumes the decla
ration has the unknown type. If a generic type is used but type arguments are no
t provided, then the type arguments default to the unknown type. |
5820 | 5849 |
5821 \commentary{This means that given a generic declaration $G<T_1, \ldots, T_n>$, t
he type $G$ is equivalent to $G< \DYNAMIC{}, \ldots, \DYNAMIC{}>$. | 5850 \commentary{This means that given a generic declaration $G<T_1, \ldots, T_n>$, t
he type $G$ is equivalent to $G< \DYNAMIC{}, \ldots, \DYNAMIC{}>$. |
5822 } | 5851 } |
5823 | 5852 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5862 The only subtype relations that pertain to void are therefore: | 5891 The only subtype relations that pertain to void are therefore: |
5863 \begin{itemize} | 5892 \begin{itemize} |
5864 \item | 5893 \item |
5865 $\VOID{} <: \VOID{}$ (by reflexivity) | 5894 $\VOID{} <: \VOID{}$ (by reflexivity) |
5866 \item | 5895 \item |
5867 $\bot <: \VOID{}$ (as bottom is a subtype of all types). | 5896 $\bot <: \VOID{}$ (as bottom is a subtype of all types). |
5868 \item | 5897 \item |
5869 $\VOID{} <: \DYNAMIC{}$ (as \DYNAMIC{} is a supertype of all types) | 5898 $\VOID{} <: \DYNAMIC{}$ (as \DYNAMIC{} is a supertype of all types) |
5870 \end{itemize} | 5899 \end{itemize} |
5871 | 5900 |
| 5901 The analogous rules also hold for the $<<$ relation for similar reasons. |
| 5902 |
5872 Hence, the static checker will issue warnings if one attempts to access a member
of the result of a void method invocation (even for members of \NULL{}, such as
\code{==}). Likewise, passing the result of a void method as a parameter or as
signing it to a variable will cause a warning unless the variable/formal paramet
er has type dynamic. | 5903 Hence, the static checker will issue warnings if one attempts to access a member
of the result of a void method invocation (even for members of \NULL{}, such as
\code{==}). Likewise, passing the result of a void method as a parameter or as
signing it to a variable will cause a warning unless the variable/formal paramet
er has type dynamic. |
5873 | 5904 |
5874 On the other hand, it is possible to return the result of a void method from wit
hin a void method. One can also return \NULL{}; or a value of type \DYNAMIC{}. R
eturning any other result will cause a type warning. In checked mode, a dynamic
type error would arise if a non-null object was returned from a void method (sin
ce no object has runtime type \DYNAMIC{}). | 5905 On the other hand, it is possible to return the result of a void method from wit
hin a void method. One can also return \NULL{}; or a value of type \DYNAMIC{}. R
eturning any other result will cause a type warning. In checked mode, a dynamic
type error would arise if a non-null object was returned from a void method (sin
ce no object has runtime type \DYNAMIC{}). |
5875 } | 5906 } |
5876 | 5907 |
5877 \commentary {The name \VOID{} does not denote a \cd{Type} object.} | 5908 \commentary {The name \VOID{} does not denote a \cd{Type} object.} |
5878 | 5909 |
5879 \rationale { | 5910 \rationale { |
5880 It is syntacticly illegal to use \VOID{} as an expression, and it would make no
sense to do so. | 5911 It is syntacticly illegal to use \VOID{} as an expression, and it would make no
sense to do so. |
5881 Type objects reify the runtime types of instances. No instance ever has type \VO
ID{}. | 5912 Type objects reify the runtime types of instances. No instance ever has type \VO
ID{}. |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6052 \item The names of compile time constant variables never use lower case letters.
If they consist of multiple words, those words are separated by underscores. Ex
amples: PI, I\_AM\_A\_CONSTANT. | 6083 \item The names of compile time constant variables never use lower case letters.
If they consist of multiple words, those words are separated by underscores. Ex
amples: PI, I\_AM\_A\_CONSTANT. |
6053 \item The names of functions (including getters, setters, methods and local or l
ibrary functions) and non-constant variables begin with a lowercase letter. If t
he name consists of multiple words, each word (except the first) begins with an
uppercase letter. No other uppercase letters are used. Examples: camlCase, dar
t4TheWorld | 6084 \item The names of functions (including getters, setters, methods and local or l
ibrary functions) and non-constant variables begin with a lowercase letter. If t
he name consists of multiple words, each word (except the first) begins with an
uppercase letter. No other uppercase letters are used. Examples: camlCase, dar
t4TheWorld |
6054 \item The names of types (including classes and type aliases) begin with an uppe
r case letter. If the name consists of multiple words, each word begins with
an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D
art4TheWorld. | 6085 \item The names of types (including classes and type aliases) begin with an uppe
r case letter. If the name consists of multiple words, each word begins with
an uppercase letter. No other uppercase letters are used. Examples: CamlCase, D
art4TheWorld. |
6055 \item The names of type variables are short (preferably single letter). Examples
: T, S, K, V , E. | 6086 \item The names of type variables are short (preferably single letter). Examples
: T, S, K, V , E. |
6056 \item The names of libraries or library prefixes never use upper case letters. I
f they consist of multiple words, those words are separated by underscores. Exam
ple: my\_favorite\_library. | 6087 \item The names of libraries or library prefixes never use upper case letters. I
f they consist of multiple words, those words are separated by underscores. Exam
ple: my\_favorite\_library. |
6057 \end{itemize} | 6088 \end{itemize} |
6058 } | 6089 } |
6059 | 6090 |
6060 | 6091 |
6061 \end{document} | 6092 \end{document} |
OLD | NEW |