I use Dhall for simple application configuration, so there are no imports - which means in theory I should be able to parse config.dhall
without IO.
In #354, Gabriel provided some hints, so I attempted the following very-rough implementation to get something working:
parsePure :: Text -> Config
parsePure (mergeWithDefault -> cfgText) =
either (error . show) id
$ validationToEither
$ Dhall.extract @Config Dhall.auto
$ Dhall.Core.normalize
$ either (error . show) id
$ Dhall.TypeCheck.typeOf
$ flip Dhall.Substitution.substitute Dhall.Substitution.empty
$ fromMaybe (error "imports")
$ traverse (\_ -> Nothing)
$ either (error . show) id
$ Dhall.Parser.exprFromText "neuron.dhall" cfgText
(Full diff here: https://github.com/srid/neuron/pull/267/files )
However, this leads to the following flurry of errors:
Multiple errors were encountered during extraction:
Error: Invalid Dhall.Decoder
Every Decoder must provide an extract function that succeeds if an expression
matches the expected type. You provided a Decoder that disobeys this contract
The Decoder provided has the expected dhall type:
↳ { aliases : List Text, author : Optional Text }
and it couldn't extract a value from the well-typed expression:
↳ { aliases : List Text
, author : Optional Text
, editUrl : Optional Text
, mathJaxSupport : Bool
, minVersion : Text
, siteBaseUrl : Optional Text
, siteTitle : Text
, theme : Text
}
Error: Invalid Dhall.Decoder
Every Decoder must provide an extract function that succeeds if an expression
matches the expected type. You provided a Decoder that disobeys this contract
The Decoder provided has the expected dhall type:
↳ { editUrl : Optional Text, mathJaxSupport : Bool }
and it couldn't extract a value from the well-typed expression:
↳ { aliases : List Text
, author : Optional Text
, editUrl : Optional Text
, mathJaxSupport : Bool
, minVersion : Text
, siteBaseUrl : Optional Text
, siteTitle : Text
, theme : Text
}
Error: Invalid Dhall.Decoder
Every Decoder must provide an extract function that succeeds if an expression
matches the expected type. You provided a Decoder that disobeys this contract
The Decoder provided has the expected dhall type:
↳ { minVersion : Text, siteBaseUrl : Optional Text }
and it couldn't extract a value from the well-typed expression:
↳ { aliases : List Text
, author : Optional Text
, editUrl : Optional Text
, mathJaxSupport : Bool
, minVersion : Text
, siteBaseUrl : Optional Text
, siteTitle : Text
, theme : Text
}
Error: Invalid Dhall.Decoder
Every Decoder must provide an extract function that succeeds if an expression
matches the expected type. You provided a Decoder that disobeys this contract
The Decoder provided has the expected dhall type:
↳ { siteTitle : Text, theme : Text }
and it couldn't extract a value from the well-typed expression:
↳ { aliases : List Text
, author : Optional Text
, editUrl : Optional Text
, mathJaxSupport : Bool
, minVersion : Text
, siteBaseUrl : Optional Text
, siteTitle : Text
, theme : Text
}
I checked the implementation of inputHelper
which more or less does the same thing. Does anyone have any idea of what I might be missing?
Overall, it would be good to have an example of how to purely parse a simple Dhall file (no imports).