question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enum with single value not supported as LF enum

See original GitHub issue

It’s not possible to use an enum with a single value in DAML that would translate to a LF enum, e.g. data myEnum = myEnumA. The recommended workaround is to write data myEnum = myEnumA (), but this translates to a variant.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
jberthold-dacommented, Oct 30, 2019

Correct. What I would like is that

  • data X = X compiles to a singleton LF Enum It won’t be a problem if
  • data X = X () compiles to a variant, and
  • data X = X {} compiles to an empty record although I struggle to see the utility of the two latter ones.
0reactions
cocreaturecommented, Oct 31, 2019

I thought a bit about the implementation and I believe it should be fairly straightforward:

  1. When translating the definition of a datatype look at the parsed source to figure out how to translate it.
  2. When translating a pattern match figure out the module and package of the corresponding data type (you can get that info from the DataCon) and look at the DALF for that module to see how we desugared it previously.
Read more comments on GitHub >

github_iconTop Results From Across the Web

It is proper to have an enum with a single value?
it means absence of a user ID, and if it's 42 , then that's the user ID. With an enum type with only...
Read more >
enum — Support for enumerations — Python 3.11.1 ...
Allows Enum members to have attributes without conflicting with member names. unique(). Enum class decorator that ensures only one name is bound to...
Read more >
Build Enumerations of Constants With Python's Enum
In this tutorial, you'll learn how to create and use enumerations of semantically related constants in Python. To do this, you'll use the ......
Read more >
Documentation: 15: 8.7. Enumerated Types - PostgreSQL
Enumerated (enum) types are data types that comprise a static, ordered set of values. They are equivalent to the enum types supported in...
Read more >
Handbook - Enums - TypeScript
It does not have an initializer and the preceding enum member was a numeric constant. In this case the value of the current...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found