Skip to content

Commit 81a837f

Browse files
committed
WIP
1 parent 70be01a commit 81a837f

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

SPEC.md

Lines changed: 55 additions & 11 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

@@ -3397,7 +3441,7 @@ struct Invalid {
33973441

33983442
## Enum Definition
33993443

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.
34013445

34023446
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 (`{}`).
34033447

@@ -3411,8 +3455,8 @@ enum Color {
34113455

34123456
An enum can be thought of as two different constructs sharing the same name:
34133457

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`.
34163460

34173461
For example, the above definition of `Color` can be thought of as shorthand for:
34183462

@@ -3442,13 +3486,13 @@ Keep in mind that the above example is illustrative - it is not actually possibl
34423486

34433487
### Enum Usage
34443488

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.
34463490

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.
34483492

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 `>`, `>=`, `<`, `<=`).
34503494

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]().
34523496

34533497
```wdl
34543498
version 1.2
@@ -3675,7 +3719,7 @@ struct Patient {
36753719

36763720
### Importing and Aliasing Enums
36773721

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).
36793723

36803724
```wdl
36813725
version 1.2

0 commit comments

Comments
 (0)