dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
908 stars 211 forks source link

Translate to dhall as a collection of expressions connected by imports #2476

Open j-rockel opened 1 year ago

j-rockel commented 1 year ago

This is more of a "is there any way to do this / could this functionality be supported in future" question rather than an issue:

When translating from haskell to dhall, I want to have my output be a collection of dhall files connected by imports rather than one big file. Currently I'm doing this by translating and then traversing the resulting dhall expression, splitting out subexpressions and replacing them with import statements, but I would much prefer to be able to mark a split point in the haskell representation rather than having to scan for it in the dhall expression.

The two initial ideas I had for this are both currently not supported as far as I can tell:

  1. A custom ToDhall instance that would produce an import statement / an expression containing imports / a list of expressions containing imports and their respective subpaths ... -> can't do that bc the types of embed and declared are limited to import free expressions
  2. Build my own ToSplitDhall typeclass to do this -> the problem with this is a bit harder to express but I think the core of the issue here is that I can't find a way to build an expression with a hole that I can slot an existing subexpression into

Am I missing something and there is already a way to do this? If not, was it intentionally omitted or just hasn't been needed so far?

Gabriella439 commented 1 year ago

Yeah, you wouldn't be able to do this using ToDhall since they can only emit a single Expr and not, say, a directory tree of expressions.

If you were to try to create a ToSplitDhall type class, I think what you'd want is something like:

toSplitDhall :: a -> DirectoryTree (Expr Src Void)

… where DirectoryTree is some pure representation of a directory tree

j-rockel commented 1 year ago

yeah that's what I thought, but even then I am still restricted to Expr Src Void so no imports (unless I purposely misuse the import type parameter, which I'd rather not), meaning I would still have to go through the resulting expressions and replace subexpressions with import statements, right?

Gabriella439 commented 1 year ago

Oh yeah, in the latter toSplitDhall example you'd have to change it to Expr Src Import