Count representable and valid job states

A job tracker currently stores every job as a record containing all four fields below. Each field is an enumeration: its listed names are distinct values with no associated data. Initially, every combination of field values is permitted by the record type.


Field

Permitted values

state

Ready, Failed, Waiting

stage

S0, S1, S2, S3

worker

A, B, C

error

None, Disk, Network, Input


The application imposes additional business rules:


State

Required field conditions

Ready

error is None; stage and worker may have any listed values

Failed

stage is S0; worker is A; error is Disk, Network or Input

Waiting

stage is S0; worker is A; error is None


A proposed replacement is a tagged union, which stores exactly one named alternative together with that alternative's fields. Its alternatives are Ready(stage, worker), Failed(error) and Waiting. In this replacement, Ready uses the four listed stages and three listed workers, Failed uses only Disk, Network or Input, and Waiting has no fields.


Count values by their contents: changing any stored field or the selected alternative produces a different value. Report these three quantities as exact integers:

  • The total number of values permitted by the original record type before applying the business rules.
  • The number of those record values that violate at least one business rule.
  • The total number of values permitted by the replacement tagged union.
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Type Systems Questions: