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

Data instance for Expr. #418

Merged
merged 6 commits into from
Jun 4, 2018
Merged

Data instance for Expr. #418

merged 6 commits into from
Jun 4, 2018

Conversation

sellout
Copy link
Collaborator

@sellout sellout commented Jun 1, 2018

Fixes #416.

Also adds some Template Haskell to be able to load & resolve a Dhall expression
at compile-time.

Without the Data instance, the AST had to be pretty-printed back to a String
in the Template Haskell, and in 1.14 imports now auto-normalize, which often
results in much larger ASTs, and therefore (at least with the current version)
much longer parses after re-serialization. Adding the Data instance avoids
that.

The current implementation of the Data instance removes
Data.Text.Lazy.Builder in favor of using Data.Text.Lazy directly, this is
simply because the latter already has a Data instance. It’s probably
reasonable to instead have a non-derived Data instance for Chunks that
explicitly uses to/fromLazyText, but that approach was less mechanical, so I
punted on it.

Fixes dhall-lang#416.

Also adds some Template Haskell to be able to load & resolve a Dhall expression
at compile-time.

Without the `Data` instance, the AST had to be pretty-printed back to a `String`
in the Template Haskell, and in 1.14 imports now auto-normalize, which often
results in much larger ASTs, and therefore (at least with the current version)
_much_ longer parses after re-serialization. Adding the `Data` instance avoids
that.

The current implementation of the `Data` instance removes
`Data.Text.Lazy.Builder` in favor of using `Data.Text.Lazy` directly, this is
simply because the latter already has a `Data` instance. It’s probably
reasonable to instead have a non-derived `Data` instance for `Chunks` that
explicitly uses `to`/`fromLazyText`, but that approach was less mechanical, so I
punted on it.
@sellout
Copy link
Collaborator Author

sellout commented Jun 1, 2018

Another thing I’d like to do with this is somehow have staticLoadWith be able to call addDependentFile on each import (at least the file imports), so that code using staticDhallExpression is recompiled if any of the imports are modified.

dhall.cabal Outdated
@@ -176,6 +176,7 @@ Library
prettyprinter >= 1.2.0.1 && < 1.3 ,
prettyprinter-ansi-terminal >= 1.1.1 && < 1.2 ,
scientific >= 0.3.0.0 && < 0.4 ,
template-haskell ,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add an upper bound to template-haskell

src/Dhall/TH.hs Outdated

importDhallExpression :: Text.Text -> IO (D.Expr D.Src D.X)
importDhallExpression =
either (const (fail "invalid Dhall expression")) D.load
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps include the name Dhall.TH.importDhallExpression in the error string so that it's easier for people to hunt down the source for where the error originates from

@@ -0,0 +1,28 @@
{-# LANGUAGE TemplateHaskell #-}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a module header explaining an example use case for this functionality?

{-| Similar to `input`, but without interpreting the Dhall `Expr` into a Haskell
type.
-}
inputExpr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very handy! Thanks for adding this :)

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

Successfully merging this pull request may close these issues.

Data instance for Expr Src X
2 participants