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

Users cannot omit fields of a record. #225

Closed
vmchale opened this issue Jan 22, 2018 · 7 comments
Closed

Users cannot omit fields of a record. #225

vmchale opened this issue Jan 22, 2018 · 7 comments

Comments

@vmchale
Copy link
Collaborator

vmchale commented Jan 22, 2018

I quite like Dhall from what I've seen so far. However, one of the pain points I noticed (compared to TOML) is that the user cannot simply omit a field of a record. If library authors were able to make values of type Maybe Text and have these omitted when writing the actual configuration, it would be much easier for users down the line.

Thanks for all the work on this language! I'm using it in a project and am excited to see where it goes :)

@ocharles
Copy link
Member

As Optional is actually part of the core language this feels like it might be possible. Don't hold me to that, though 😄

@ocharles
Copy link
Member

ocharles commented Jan 22, 2018

I should note that this is possible, in a sense, using the current version of Dhall. What changes here is that you can no longer provide a canonical type of the expression that your users give you. The process is essentially:

  • Read Text
  • Parse a Dhall 'Expr`
  • Resolve imports
  • Type check the result - only to make sure it is well formed
  • Turn the Expr into whatever type you need by walking through it.

It's in the last step that you can start to do things like:

case expr of
  RecordLit fields -> do
    myFoo <-
      case Map.lookup "foo" fields of
        Just fooExpr -> Just <$>_ fooExpr
        Nothing -> return Nothing

Does that make sense? The difference here is that you aren't using Dhall.input, as Dhall.input tries to annotate the given input Expr with a specific type (it literally appends : T, for some T to drive the type-checking process).

@Gabriella439
Copy link
Collaborator

Yeah, the main issue here is that you would no longer be able to infer a canonical type for a expression

I recommend instead providing a record where all the Optional fields are empty that you can then override that using //, like this:

    let defaults = { bar = [] : Optional Bool, foo = [] : Optional Text }

in  defaults ⫽ { bar = [ True ] : Optional Bool, baz = 1 }

@ocharles
Copy link
Member

Here is my above mentioned approach explored in the context of dhall-to-cabal: dhall-lang/dhall-to-cabal@e154561.

I must admit, I find it quite compelling, even at the cost of losing a canonical type.

@Gabriella439
Copy link
Collaborator

I think dhall-to-cabal is one case where you really want a canonical type. As I mentioned in #78, I think one of the most important outcomes of dhall-to-cabal is not only the executable, but a complete Dhall schema for a cabal configuration file.

@ocharles
Copy link
Member

ocharles commented Jan 22, 2018

I've opened dhall-lang/dhall-to-cabal#12 to continue that discussion, rather than hijack @vmchale's original question.

@vmchale
Copy link
Collaborator Author

vmchale commented Jan 23, 2018

Great, thanks! This should work well enough for now :)

@vmchale vmchale closed this as completed Jan 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants