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
+55-11Lines changed: 55 additions & 11 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
1568
+
# values "FASTQ" and "BAM" respectively.
1569
+
enum FileKind {
1570
+
FASTQ,
1571
+
BAM
1572
+
}
1573
+
```
1530
1574
1531
1575
#### Hidden and Scoped Types
1532
1576
@@ -3397,7 +3441,7 @@ struct Invalid {
3397
3441
3398
3442
## Enum Definition
3399
3443
3400
-
An `Enum` is an enumerated type. Enums enable the creation of types that represent closed sets of alternatives (called "variants") that are semantically valid in a specific context. Once defined, an `Enum` type can be used as the type of a declaration like any other type. However, new variants of an `Enum` cannot be created. Instead, a declaration having an `Enum` type must be assigned one of the variants created as part of the `Enum`'s definition.
3444
+
An `enum` is an enumerated type. Enums enable the creation of types that represent closed sets of alternatives (called "variants") that are semantically valid in a specific context. Once defined, an `enum` type can be used as the type of a declaration like any other type. However, new variants of an `enum` cannot be created. Instead, a declaration having an `enum` type must be assigned one of the variants created as part of the `enum`'s definition.
3401
3445
3402
3446
An enum definition is a top-level WDL element, meaning it is defined at the same level as tasks, workflows, and structs, and it cannot be defined within a task or workflow body. An enum is defined using the `enum` keyword, followed by a name that is unique within the WDL document, and a body containing a comma-delimited list of varaints in braces (`{}`).
3403
3447
@@ -3411,8 +3455,8 @@ enum Color {
3411
3455
3412
3456
An enum can be thought of as two different constructs sharing the same name:
3413
3457
3414
-
* A `Struct` with one `String`-type member, `name`, whose value is the "stringified" version of the variant's identifier. For example, the name of `Color.RED` is `"RED"`. Unlike structs, it is not possible to create new instances of an `Enum` outside of the enum's definition.
3415
-
* A global variable of type `Object` whose members have names equal to the enum variant names, and whose values are instances of the `Enum`.
3458
+
* A `Struct` with one `String`-type member, `name`, whose value is the "stringified" version of the variant's identifier. For example, the name of `Color.RED` is `"RED"`. Unlike structs, it is not possible to create new instances of an `enum` outside of the enum's definition.
3459
+
* A global variable of type `Object` whose members have names equal to the enum variant names, and whose values are instances of the `enum`.
3416
3460
3417
3461
For example, the above definition of `Color` can be thought of as shorthand for:
3418
3462
@@ -3442,13 +3486,13 @@ Keep in mind that the above example is illustrative - it is not actually possibl
3442
3486
3443
3487
### Enum Usage
3444
3488
3445
-
An `Enum`'s variants are [accessed](#member-access) using a `.` to separate the variant name from the `Enum`'s identifier. Each variant has single member, `String name`, that can be accessed through a `.` separator.
3489
+
An `enum`'s variants are [accessed](#member-access) using a `.` to separate the variant name from the `enum`'s identifier. Each variant has single member, `String name`, that can be accessed through a `.` separator.
3446
3490
3447
-
A declaration with an `Enum` type can only be initialized by referencing a variant directly or by assigning it to the value of another declaration of the same `Enum` type.
3491
+
A declaration with an `enum` type can only be initialized by referencing a variant directly or by assigning it to the value of another declaration of the same `enum` type.
3448
3492
3449
-
Two enum values can be tested for equality (i.e., using `==` or `!=`). To be equal, two enum values must be the same variant of the same `Enum` type. Enum variants are not ordered, so they cannot be compared (i.e., using `>`, `>=`, `<`, `<=`).
3493
+
Two enum values can be tested for equality (i.e., using `==` or `!=`). To be equal, two enum values must be the same variant of the same `enum` type. Enum variants are not ordered, so they cannot be compared (i.e., using `>`, `>=`, `<`, `<=`).
3450
3494
3451
-
An `Enum` cannot be coerced to or from any other type. However, an enum value can be [serialized to/deserialized from a `String`]() or to/from [JSON]().
3495
+
An `enum` cannot be coerced to or from any other type. However, an enum value can be [serialized to/deserialized from a `String`]() or to/from [JSON]().
3452
3496
3453
3497
```wdl
3454
3498
version 1.2
@@ -3675,7 +3719,7 @@ struct Patient {
3675
3719
3676
3720
### Importing and Aliasing Enums
3677
3721
3678
-
Enums are [imported in the same way as `Struct`s](#struct-namespacing) and have the same namespacing rules, namely that Enums exist in the document's global scope, and importing an `Enum` copies its definition into the global scope of the importing document (potentially using an alias).
3722
+
Enums are [imported in the same way as `Struct`s](#struct-namespacing) and have the same namespacing rules, namely that Enums exist in the document's global scope, and importing an `enum` copies its definition into the global scope of the importing document (potentially using an alias).
0 commit comments