I read the excellent 24 days of hackage. And i would like to give a try to the package configurator
how can i retrieve a list of data like
herlist = [1, "foo", true] ?
If you have the line
herlist = [1, "foo", true]
in a configuration file called "example.cfg", then the simplest program to load and show that value would be
{-# LANGUAGE OverloadedStrings #-}
import Data.Configurator
import Data.Configurator.Types (Value)
main = do
cfg <- load [Required "example.cfg"]
lst <- require cfg "herlist" :: IO Value
print lst
The OverloadedStrings
extension is used so that we can use ordinary string literals as configuration keys without having to explicitly convert them to Text
.
When looking up the key "herlist"
we need to explicitly tell the compiler the type we are expecting, because in a simple program like this where we do nothing but print the value, the compiler cannot infer it from context.
The type Value
is the raw type for configuration values. In a real program we would usually convert the Value
into a custom type used by our program by defining an instance of the Configured
type-class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With