Coder Social home page Coder Social logo

Comments (3)

Gabriella439 avatar Gabriella439 commented on June 5, 2024

Yeah, I think it's a good idea to only make the type annotation required for empty lists

There are a couple of minor details, but I don't think they are a big deal:

  • If a List has elements of different types there is no way to tell which element type was the intended type. In this case we can fall back on assuming that the first element type is the intended type
  • Optional values also use a list literal syntax, but I can just say that if a list literal with one element has no type annotation that it must be a List and not an Optional value

from dhall-haskell.

Profpatsch avatar Profpatsch commented on June 5, 2024

Ah, I get why you wouldn’t want NonEmpty as default, because it should be able to map to programming languages easily.

from dhall-haskell.

Gabriella439 avatar Gabriella439 commented on June 5, 2024

The other reason that I avoid NonEmpty is I would prefer Liquid-Haskell-style refinements on types if I went down that route. For example, you can model NonEmpty using refinement types like this:

NonEmpty a = { xs : List a | 1 <= length xs }

In fact, when I was adding Optional to the language, one of the design decisions was whether or not Optional would be a special case of a list with a refinement like this:

Optional a = { xs : List a | length xs <= 1 }

This is one of the reasons that Optionals use the same literal syntax as lists so that I could leave the door open to possibly adding that later if I changed my mind.

The reason I decided against it in the end was because Dhall has a pretty consistent "no subtyping" rule because subtyping makes the language harder to teach to new users and refinement types are one form of subtyping. However, a more expert-friendly fork of Dhall could add something like this to the language.

from dhall-haskell.

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.