Skip to content

Commit

Permalink
Move contents of PR 464 on top of wdl-1.2 (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdidion authored May 16, 2024
1 parent 6ab6122 commit 89d32f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ version 1.2.0

+ Added parameters to `read_tsv` that enable it to read field names from a header row or an `Array[String]` and return an `Array[Object]`. [PR 627](https://github.com/openwdl/wdl/pull/627)

+ Clarify how inputs with defaults are implicitly optional
[PR 464](https://github.com/openwdl/wdl/pull/464) by @mlin

+ Make `input:` optional in call bodies.
[PR 524](https://github.com/openwdl/wdl/pull/524) by @mlin.

Expand Down
18 changes: 13 additions & 5 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ Example output:

WDL provides the standard unary and binary mathematical and logical operators. The following tables list the valid operand and result type combinations for each operator. Using an operator with unsupported types results in an error.

In operations on mismatched numeric types (e.g., `Int` + `Float`), the `Int` is first coerced to `Float`, and the result type is `Float`. This may result in loss of precision, for example if the `Int` is too large to be represented exactly by a `Float`. A `Float` can be converted to `Int` with the [`ceil`](#ceil), [`round`](#round), or [`floor`](#floor) functions.
In operations on mismatched numeric types (e.g., `Int` + `Float`), the `Int` is first is coerced to `Float`, and the result type is `Float`. This may result in loss of precision, for example if the `Int` is too large to be represented exactly by a `Float`. A `Float` can be converted to `Int` with the [`ceil`](#ceil), [`round`](#round), or [`floor`](#floor) functions.

##### Unary Operators

Expand Down Expand Up @@ -3489,7 +3489,7 @@ task name {

### Task Inputs

A task's `input` section declares its input parameters. The values for declarations within the `input` section may be specified by the caller of the task. An input declaration may be initialized to a default expression that will be used when the caller does not specify a value. Input declarations may also be optional, in which case a value may be specified but is not required. If an input declaration is not optional and does not have an initialization, then it is a required input, meaning the caller must specify a value.
A task's `input` section declares its input parameters. The values for declarations within the `input` section may be specified by the caller of the task. An input declaration may be initialized to a default expression to use when the caller does not supply a value. Input declarations with the optional type quantifier `?` also may be omitted by the caller even when there is no default initializer. If an input declaration has neither an optional type nor a default initializer, then it is a required input, meaning the caller must specify a value.

<details>
<summary>
Expand Down Expand Up @@ -3596,8 +3596,8 @@ For example, imagine two versions of file `fs://path/to/A.txt` are being localiz
#### Input Type Constraints

Recall that a type may have a quantifier:
* `?` means that the parameter is optional. A user does not need to specify a value for the parameter in order to satisfy all the inputs to the workflow.
* `+` applies only to `Array` types and it represents a constraint that the `Array` value must contain one-or-more elements.

* `?` means that the input is optional and a caller does not need to specify a value for the input.* `+` applies only to `Array` types and it represents a constraint that the `Array` value must contain one-or-more elements.

The following task has several inputs with type quantifiers:

Expand Down Expand Up @@ -3703,7 +3703,15 @@ cat /tmp/file3 >> result

##### Optional inputs with defaults

It *is* possible to provide a default to an optional input type. This may be desirable in the case where you want to have a defined value by default, but you want the caller to be able to override the default and set the value to undefined (`None`).
Inputs with default initializers are implicitly optional: callers may omit the input or supply `None` *whether or not* its declared type carries the optional quantifier `?`. Usually, inputs with defaults should omit the `?` from their type, except when callers need the ability to override the default with `None`.

In detail, if a caller omits an input from the call `input:` section, then the default initializer applies whether or not the input type is declared optional. But if the caller explicitly supplies `None` for the input (either literally or by passing an optional value), then the default initializer applies only if the declared type isn't optional. This table illustrates the value taken by an input `x` depending on what the caller supplies:

| input declaration: | `Int x = 1` | `Int? x = 1` | `Int? x` | `Int x` |
| ---------------------- | ----------- | ------------ | -------- | ------- |
| call input: `x = 42` | 42 | 42 | 42 | 42 |
| call input: `x = None` | 1 | `None` | `None` | *error* |
| call input: *omitted* | 1 | 1 | `None` | *error* |

<details>
<summary>
Expand Down

0 comments on commit 89d32f5

Please sign in to comment.