You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: SPEC.md
+47-3Lines changed: 47 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1491,15 +1491,16 @@ Note that the ability to assign values to `Struct` declarations other than struc
1491
1491
1492
1492
##### Enumeration Types (Enums)
1493
1493
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.
1495
1495
1496
-
An enum is defined using the `enum` keyword, followed by a globally unique name, followed by a comma-delimited list of identifiersin 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.
1497
1497
1498
1498
```wdl
1499
1499
enum FileKind {
1500
1500
FASTQ,
1501
1501
BAM
1502
1502
}
1503
+
1503
1504
task process_file {
1504
1505
input {
1505
1506
File infile
@@ -1516,6 +1517,7 @@ workflow process_files {
1516
1517
Array[File] files
1517
1518
FileKind kind
1518
1519
}
1520
+
1519
1521
scatter (file in files) {
1520
1522
call process_file {
1521
1523
input:
@@ -1526,7 +1528,49 @@ workflow process_files {
1526
1528
}
1527
1529
```
1528
1530
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
0 commit comments