Haskell 中有典型的配置或属性文件格式和库吗?

发布于 2024-10-10 15:51:48 字数 109 浏览 6 评论 0 原文

我需要一组键值对来从文件中读取配置。我尝试在 Data.Map 上使用 show,但它看起来根本不像我想要的。看来这是许多其他人可能已经做过的事情,所以我想知道是否有标准的方法来做到这一点以及使用什么库。

I need a set of key-value pairs for configuration read in from a file. I tried using show on a Data.Map and it doesn't look at all like what I want. It seems this is something many others might have already done so I'm wondering if there is a standard way to do it and what library to use.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

娇女薄笑 2024-10-17 15:51:48
  1. 转到黑客
  2. 单击“packages
  3. 搜索“config”。
  4. 注意 ConfigFile(TH)、EEConfigtconfig
  5. 阅读 Haddock 文档
  6. 选择一对并实施您的任务。
  7. 在博客中记录您的发现,以便我们其他人可以从您新发现的专业知识中学习(谢谢!)。

编辑:
我最近使用了 配置器 - 这很简单。我建议你试试那个!

(是的,是的。如果我采纳自己的建议,我会为你们所有人创建一个博客)

  1. Go to hackage.
  2. Click on "packages"
  3. Search for "config".
  4. Notice ConfigFile(TH), EEConfig, and tconfig.
  5. Read the Haddock documentation
  6. Select a couple and implement your task.
  7. Blog about your findings so the rest of us can learn from your new found expertise (thanks!).

EDIT:
I've recently used configurator - which was easy enough. I suggest you try that one!

(Yes, yes. If I took my own advice I would have made a blog for you all)

我乃一代侩神 2024-10-17 15:51:48

Hackage 上的配置类别应列出所有相关库:
http://hackage.haskell.org/packages/#cat:Configuration

我现在我自己研究了这个主题,我的结论是:

  • 配置器非常好,但目前仅适用于用户编辑的配置。应用程序只能读取配置,不能修改它。所以它更适合服务器端应用程序。
  • tconfig 有一个简单的 API,看起来就是我想要的,可能有点原始,直到我意识到它未维护并且一些commits 这对于使用该应用程序非常重要,已在 github 上应用,但 hackage 包未更新

其他解决方案未 更新看起来它们对我有用,我不喜欢 API,但每个应用程序(和口味)都是不同的。

我认为使用 JSON 为例并不是一个好的解决方案,因为至少在 Aeson 中,当您在新版本中添加新设置时,没有先前版本中的新成员的旧 JSON 将无法加载。另外,我发现该解决方案有点冗长。

我的研究结论是,我编写了自己的库 app-settings,它目标是键值、读写,并具有尽可能简洁和类型安全的 API。您还可以在我提供的配置类别的 hackage 链接中找到它。

总而言之,我认为 configurator 是只读配置的标准(而且它非常强大例如,您也可以使用导入来分割配置文件)。对于读写,有很多小型库,其中一些没有维护,而且我认为没有真正的标准。

更新 2018 请务必查看 dhall

The configuration category on Hackage should list all relevant libraries:
http://hackage.haskell.org/packages/#cat:Configuration

I have researched the topic myself now, and my conclusion is:

  • configurator is very good, but it's currently only for user-edited configurations. The application only reads the configuration and cannot modify it. So it's more for server-side applications.
  • tconfig has a a simple API and looked like it was what I wanted, maybe a bit raw, until I realized it's unmaintained and that some commits which are really important to use the app are applied on github but the hackage package was not updated

Other solutions didn't look like they'd work for me, I didn't like the API, but every application (and tastes) are different.

I think using JSON for instance is not a good solution because at least with Aeson when you add new settings in a new release, the old JSON without the new member from the previous version won't load. Also, i find that solution a bit verbose.

The conclusion of my research is that I wrote my own library, app-settings, which aims to be key-value, read-write, with a as succint and type-safe API as possible. And you'll find it also in the hackage links for the configurations category that I gave.

So to summarize, I think configurator is the standard for read-only configurations (and it's very powerful too, you can split the configuration file with imports for instance). For read-write there are many small libraries, some unmaintained, and no real standard I think.

UPDATE 2018 be sure to look at dhall

若无相欠,怎会相见 2024-10-17 15:51:48

我还建议仅使用 Text.JSON 或可用的 yaml 库之一(我自己更喜欢 JSON,但是......)。

I'd also suggest just using Text.JSON or one of the yaml libraries available (I prefer JSON myself, but...).

〆凄凉。 2024-10-17 15:51:48

configfile 包 看起来像你想要的。

The configfile package looks like what you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文