Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a typical config or property file format and library in Haskell?

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.

like image 968
mentics Avatar asked Jan 06 '11 14:01

mentics


4 Answers

  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)

like image 148
Thomas M. DuBuisson Avatar answered Sep 30 '22 18:09

Thomas M. DuBuisson


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

like image 34
Emmanuel Touzery Avatar answered Sep 30 '22 17:09

Emmanuel Touzery


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

like image 4
sclv Avatar answered Sep 30 '22 17:09

sclv


The configfile package looks like what you want.

like image 3
sepp2k Avatar answered Sep 30 '22 19:09

sepp2k