Is there an elegant way to "override" Dhall records in Haskell?

92 Views Asked by At

I'm using Dhall to accept user configurations. Some field are compulsory while the others are optional, whose default values should be used when left unspecified by the user. This is what I currently have:

override :: FilePath  -- user
         -> FilePath  -- default
         -> IO Config
override user def = parseConfig $ def ++ " // " ++ user

finalConfig :: IO Config
finalConfig = do user <- getUserConfig
                 def <- getDataFileName "defaults.dhall"
                 return (user `override` defaults)

Clearly concatenating file paths and inserting the // operator is dirty enough. I wonder if there is a more elegant approach to this.

1

There are 1 best solutions below

0
Gabriella Gonzalez On

So this is not something that is ergonomic to do using the current Haskell API, but I just put up a pull request to add a few new utilities that would make this easier. Once that is merged and released, you'd be able to interpret and decode an Expr instead of Text so that you don't have to work with raw strings.