Skip to content

Commit 53d28e9

Browse files
committed
WIP
1 parent 70be01a commit 53d28e9

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

SPEC.md

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,15 +1491,16 @@ Note that the ability to assign values to `Struct` declarations other than struc
14911491

14921492
##### Enumeration Types (Enums)
14931493

1494-
An enumeration (or "enum") is a closed set of alternatives that are considered semantically valid in a specific context. An enum is [defined]() at the top-level of the WDL document and can be used as a declaration type anywhere in the document.
1494+
An enumeration (or "enum") is a closed set of enumerated values (known as "variants") that are considered semantically valid in a specific context. An enum is defined at the top-level of the WDL document and can be used as a declaration type anywhere in the document.
14951495

1496-
An enum is defined using the `enum` keyword, followed by a globally unique name, followed by a comma-delimited list of identifiers in braces. The value for an enum cannot be created; rather, it must be selected from the list of available values using the `<name>.<value>` syntax.
1496+
An enum is defined using the `enum` keyword, followed by a globally unique name, followed by a comma-delimited list of identifiers—optionally tagged with values—in braces. When referring to a variant within an enum, for example, when assigning to an enum declaration, the `<name>.<variant>` syntax should be used.
14971497

14981498
```wdl
14991499
enum FileKind {
15001500
FASTQ,
15011501
BAM
15021502
}
1503+
15031504
task process_file {
15041505
input {
15051506
File infile
@@ -1516,6 +1517,7 @@ workflow process_files {
15161517
Array[File] files
15171518
FileKind kind
15181519
}
1520+
15191521
scatter (file in files) {
15201522
call process_file {
15211523
input:
@@ -1526,7 +1528,49 @@ workflow process_files {
15261528
}
15271529
```
15281530

1529-
As an example, consider a workflow that processes different types of NGS files and has a `file_kind` input parameter that is expected to be either "fastq" or "bam". Using `String` as the type of `file_kind` is not ideal - if the user specifies an invalid value, the error will not be caught until runtime, perhaps after the workflow has already run for several hours. Alternatively, using an `enum` type for `file_kind` restricts the allowed values such that the execution engine can validate the input prior to executing the workflow.
1531+
As an example, consider a workflow that processes different types of NGS files and has a `file_kind` input parameter that is expected to be either "FASTQ" or "BAM". Using `String` as the type of `file_kind` is not ideal - if the user specifies an invalid value, the error will not be caught until runtime, perhaps after the workflow has already run for several hours. Alternatively, using an `enum` type for `file_kind` restricts the allowed values such that the execution engine can validate the input prior to executing the workflow.
1532+
1533+
Enums are valued, meaning that each variant within an enum has an associated value. To assign a type to the values therein, enums can either be _explicitly_ or _implicitly_ typed.
1534+
1535+
* Explicitly typed enums take an explicit type assigment within square brackets after the enum's identifier that declares the type of the value. Where possible, explicitly typed enums should resolve ambiguities via coercion.
1536+
* Implicitly typed enums are enums where the values can be unambiguously mapped to a single [primitive type](#primitive-types). Enums that are implicitly typed and for which no values are assigned are assumed to be `String` valued with values matching the variant names. All values within an enum must have the same type or an error is thrown.
1537+
1538+
```wdl
1539+
# An explicitly typed enum that is `String`-valued.
1540+
enum FruitColors[String] {
1541+
Banana = "yellow",
1542+
Orange = "orange",
1543+
Apple = "red",
1544+
}
1545+
1546+
# An explicitly typed enum that is `Float`-valued. Because the enum is
1547+
# explicitly typed, the `ThreePointOh` variant can be coerced to a `Float`,
1548+
# which is a valid enumeration definition.
1549+
enum FavoriteFloat[Float] {
1550+
ThreePointOh = 3,
1551+
FourPointOh = 4.0
1552+
}
1553+
1554+
# ERROR: because the enum is implicitly typed, the type cannot be unambiguously
1555+
# resolved, which results in an error.
1556+
enum FavoriteNumber {
1557+
ThreePointOh = 3,
1558+
FourPointOh = 4.0
1559+
}
1560+
1561+
# An implicitly typed enum that is `String`-valued.
1562+
enum Whitespace {
1563+
Tab = "\t",
1564+
Space = " "
1565+
}
1566+
1567+
# An implicitly typed enum that is implied to be `String`-valued with the
1568+
# values "FASTQ" and "BAM" respectively.
1569+
enum FileKind {
1570+
FASTQ,
1571+
BAM
1572+
}
1573+
```
15301574

15311575
#### Hidden and Scoped Types
15321576

0 commit comments

Comments
 (0)