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:
我正在使用DHall接受用户配置。一些字段是必填的,而另一些是可选的,当用户未指定时,应使用其缺省值。这就是我目前所拥有的:
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.
显然,连接文件路径和插入//操作符已经够脏的了。我想知道是否有更优雅的方法来解决这一问题。
更多回答
优秀答案推荐
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.
因此,这不是使用当前的Haskell API所能完成的符合人体工程学的事情,但我只是提出了一个拉请求,以添加一些新的实用程序来简化这一过程。一旦合并并发布,您将能够解释和解码expr而不是文本,这样您就不必处理原始字符串。
更多回答
我是一名优秀的程序员,十分优秀!