gpt4 book ai didi

Is there an elegant way to "override" Dhall records in Haskell?(有没有一种优雅的方法来“覆盖”Haskell中的DHall记录?)

转载 作者:bug小助手 更新时间:2023-10-24 23:15:34 28 4
gpt4 key购买 nike



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而不是文本,这样您就不必处理原始字符串。


更多回答

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com