5. One operator for either-or
The | operator means "one of these", and it is the same operation whether the alternatives are values, an enum, or types, a sum type.

5. One operator for either-or

The | operator means "one of these", and it is the same operation whether the alternatives are values, an enum, or types, a sum type.

Two features that other languages keep apart collapse into one, because types are values.

The pipe means: one of these. Info, or warn, or error. Other languages call this an enum.

Int or string. Other languages call this a sum type: a value that may be one of several types.

To CUE they are the same operation. Types are values, so there is nothing to tell apart.

It is a menu. A menu can list single dishes, or whole kinds of dish. Either way, it is a list of choices.

Unify a menu with a choice, and you get the choice.

Choose something that is not on it, and you get bottom.

Check yourself. Why does CUE not need separate features for enums and sum types?

Do you like what you are reading? Subscribe to receive updates.

Unsubscribe anytime

Comments