-
Notifications
You must be signed in to change notification settings - Fork 210
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
Conversation
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.
Another thing I’d like to do with this is somehow have |
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 , |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 #-} | |||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 :)
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 aString
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 avoidsthat.
The current implementation of the
Data
instance removesData.Text.Lazy.Builder
in favor of usingData.Text.Lazy
directly, this issimply because the latter already has a
Data
instance. It’s probablyreasonable to instead have a non-derived
Data
instance forChunks
thatexplicitly uses
to
/fromLazyText
, but that approach was less mechanical, so Ipunted on it.