Giter Site home page Giter Site logo

Enum Types about dhall-lang HOT 6 CLOSED

dhall-lang avatar dhall-lang commented on September 26, 2024
Enum Types

from dhall-lang.

Comments (6)

nbouscal avatar nbouscal commented on September 26, 2024 7

Just a note for anyone else finding this from Google, constructors was deprecated because it's no longer necessary. Enums like in the original request are now basically supported, you can do this:

let Enum = < A | B >
in [ Enum.A, Enum.B ]

from dhall-lang.

Gabriella439 avatar Gabriella439 commented on September 26, 2024 2

@srid @Koshroy : Note that newer versions of Dhall have a constructors keyword, which provides a nicer solution to this problem. You can now do:

    let type = constructors < A : {} | B : {} >

in [ type.A {=}, type.B {=} ]

from dhall-lang.

Gabriella439 avatar Gabriella439 commented on September 26, 2024

Unions are the recommended way to do this:

-- The type
< Type/A : {} | Type/B : {} >  

-- The values
< Type/A = {=} | Type/B : { } >
< Type/A : { } | Type/B = {=} >

Even if Dhall added support for enums as a special case of unions it wouldn't significantly reduce the boilerplate because an enum literal would still need to specify all other alternatives

What I do in cases like these is define synonyms for each alternative, like this:

    let Type/A = < Type/A = {=} | Type/B : { } >
in  let Type/B = < Type/A : { } | Type/B = {=} >
in  [ Type/A, Type/B, Type/B, TypeA ]

... or save the synonyms in named files:

$ cat Type/A
< Type/A = {=} | Type/B : { } >
$ cat Type/B
< Type/A : { } | Type/B = {=} >
$ cat example
[ ./Type/A , ./Type/B , ./Type/B , ./TypeA ]

This helps reduce the boilerplate so you only need to write out the full union literal once per alternative

from dhall-lang.

Koshroy avatar Koshroy commented on September 26, 2024

This answered my question! Thanks a lot!

from dhall-lang.

Gabriella439 avatar Gabriella439 commented on September 26, 2024

You're welcome! :)

from dhall-lang.

srid avatar srid commented on September 26, 2024

... or save the synonyms in named files:

This is not really practical for enums with say 10 constructors, right?

You would have ./Type/A with 9 other alternatives; likewise for Type/B, Type/C, etc.

from dhall-lang.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.