Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve doc about enum types #2168

Merged
merged 2 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions docs/source/app-dev/daml-lf-translation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ For example: the DAML pair type ``(Int, Text)`` is translated to ``daml-prim:DA.
Data types
**********

DAML-LF has two kinds of data declarations:
DAML-LF has three kinds of data declarations:

- **Record** types, which define a collection of data
- **Variant** or **sum** types, which define a number of alternatives
- **Enum**, which define simplified **sum** types without type parameters nor argument.
remyhaemmerle-da marked this conversation as resolved.
Show resolved Hide resolved

:ref:`Data type declarations in DAML <daml-ref-data-constructors>` (starting with the ``data`` keyword) are translated to either record or variant types. It’s sometimes not obvious what they will be translated to, so this section lists many examples of data types in DAML and their translations in DAML-LF.
:ref:`Data type declarations in DAML <daml-ref-data-constructors>` (starting with the ``data`` keyword) are translated to record, variant or enum types. It’s sometimes not obvious what they will be translated to, so this section lists many examples of data types in DAML and their translations in DAML-LF.

.. In the tables below, the left column uses DAML 1.2 syntax and the right column uses the notation from the `DAML-LF specification <https://github.com/digital-asset/daml/blob/master/daml-lf/spec/daml-lf-1.rst>`_.

Expand Down Expand Up @@ -102,10 +103,14 @@ Variant declarations
- DAML-LF translation
* - ``data Foo = Bar Int | Baz Text``
- ``variant Foo ↦ Bar Int64 | Baz Text``
* - ``data Foo = Bar Int | Baz ()``
- ``variant Foo ↦ Bar Int64 | Baz Unit``
* - ``data Foo = Bar Int | Baz``
- ``variant Foo ↦ Bar Int64 | Baz Unit``
* - ``data Foo a = Bar a | Baz Text``
- ``variant Foo a ↦ Bar a | Baz Text``
* - ``data Foo = Bar Unit | Baz Text``
- ``variant Foo ↦ Bar Unit | Baz Text``
* - ``data Foo = Bar Unit | Baz``
- ``variant Foo ↦ Bar Unit | Baz Unit``
* - ``data Foo a = Bar | Baz``
- ``variant Foo a ↦ Bar Unit | Baz Unit``
* - ``data Foo = Foo Int``
- ``variant Foo ↦ Foo Int64``
* - ``data Foo = Bar Int``
Expand All @@ -123,6 +128,20 @@ Variant declarations
* - ``data Foo = Bar { bar1: Int; bar2: Decimal } | Baz { baz1: Text; baz2: Date }``
- ``data Foo ↦ Bar Foo.Bar | Baz Foo.Baz``, ``record Foo.Bar ↦ { bar1: Int64; bar2: Decimal }``, ``record Foo.Baz ↦ { baz1: Text; baz2: Date }``

Enum declarations
=================

.. list-table::
:widths: 10 15
:header-rows: 1

* - DAML declaration
- DAML-LF declaration
* - ``data Foo = Bar | Baz``
- ``enum Foo ↦ Bar | Baz``
* - ``data Color = Red | Green | Blue``
- ``enum Color ↦ Red | Green | Blue``

Banned declarations
===================

Expand Down
7 changes: 5 additions & 2 deletions unreleased.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ HEAD — ongoing

+ Add support for DAML-LF intern package IDs.

- [Ledger API] Add support for ``enum`` types. Simple ``variant`` types will
be replaced by ``enum`` types when using a DAML-LF ``1.6`` archive.
- [Ledger API] Add support for ``enum`` types. Simple DAML ``variant`` types
will be mapped to DAML-LF ``enum`` types when using a DAML-LF ``1.6``
archive. Ledger API Value Protobuf provides the new ``Enum`` message.
This message must be used to communicate this new data type throught the
API.

- [Java Codegen]: Add support for ``enum`` types. ``enum`` types are mapped to
standard java enum. See `Generate Java code from DAML
Expand Down