Skip to content

Commit

Permalink
Rearrange return-types
Browse files Browse the repository at this point in the history
Prepare for #426
  • Loading branch information
jclark committed May 12, 2020
1 parent 1364866 commit 015d0af
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lang/spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -1745,22 +1745,14 @@ <h4 id="functions">Functions</h4>
<pre
class="grammar">function-type-descriptor := <code>function</code> function-signature
function-signature := <code>(</code> param-list <code>)</code> return-type-descriptor
return-type-descriptor := [ <code>returns</code> [annots] type-descriptor ]
</pre>
<p>
A function is a part of a program that can be explicitly executed. In Ballerina,
a function is also a value, implying that it can be stored in variables, and
passed to or returned from functions. When a function is executed, it is passed
an argument list as input and returns a value as output.
</p>
<p>
When the execution of a function returns to its caller, it returns exactly one
value. A function that would in other programming languages not return a value
is represented in Ballerina by a function returning <code>()</code>. Note that
the function definition does not have to explicitly return <code>()</code>; a
return statement or falling off the end of the function body will implicitly
return <code>()</code>.
</p>

<pre
class="grammar">param-list :=
required-params [<code>,</code> defaultable-params] [<code>,</code> rest-param]
Expand Down Expand Up @@ -1847,6 +1839,22 @@ <h4 id="functions">Functions</h4>
make use of arguments specified both by position and by name, is described in
more detail in the <a href="#function_call">section on function calls</a>.
</p>
<pre
class="grammar">return-type-descriptor := [ <code>returns</code> [annots] type-descriptor ]
</pre>
<p>
When the execution of a function returns to its caller, it returns exactly one
value. A function that would in other programming languages not return a value
is represented in Ballerina by a function returning <code>()</code>. Note that
the function definition does not have to explicitly return <code>()</code>; a
return statement or falling off the end of the function body will implicitly
return <code>()</code>.
</p>
<p>
The value returned by a function will belong to the type specified in the
return-type-descriptor. An empty return-type-descriptor is equivalent to
<code>returns ()</code>.
</p>
<p>
Function types are covariant in their return types and contravariant in the type
of their parameter lists. More precisely, a function type with return type R and
Expand Down

0 comments on commit 015d0af

Please sign in to comment.