libconfig-0.2.0.0: Haskell bindings to libconfig

Copyright(c) Matthew Peddie 2014
LicenseBSD3
Maintainermpeddie@gmail.com
Stabilityexperimental
PortabilityGHC
Safe HaskellNone
LanguageHaskell2010

Language.Libconfig.Types

Contents

Description

Core types for configuration file data.

Synopsis

Documentation

Here is the example configuration file test/test.conf from the libconfig manual.

     # Example application configuration file

     version = "1.0";

     application:
     {
       window:
       {
         title = "My Application";
         size = { w = 640; h = 480; };
         pos = { x = 350; y = 250; };
       };

       list = ( ( "abc", 123, true ), 1.234, ( ) );

       books = ( { title  = "Treasure Island";
                   author = "Robert Louis Stevenson";
                   price  = 29.95;
                   qty    = 5; },
                 { title  = "Snow Crash";
                   author = "Neal Stephenson";
                   price  = 9.99;
                   qty    = 8; } );

       misc:
       {
         pi = 3.141592654;
         bigint = 9223372036854775807L;
         columns = [ "Last Name", "First Name", MI ];
         bitmask = 0x1FC3;
       };
     };

The decode function renders this as the following structure:

[
  "version" := Scalar (String "1.0")
, "application" := Group [
      "window" := Group [
         "title" := Scalar (String "My Application")
       , "size" := Group [
             "w" := Scalar (Integer 640)
           , "h" := Scalar (Integer 480)
          ]
        , "pos" := Group [
             "x" := Scalar (Integer 350)
           , "y" := Scalar (Integer 250)
          ]
       ]
    , "list" := List [
          List [
             Scalar (String "abc")
           , Scalar (Integer 123)
           , Scalar (Boolean True)
          ]
        , Scalar (Float 1.234)
        , List []
       ]
    , "books" := List [
          Group [
             "title" := Scalar (String "Treasure Island")
           , "author" := Scalar (String "Robert Louis Stevenson")
           , "price" := Scalar (Float 29.95)
           , "qty" := Scalar (Integer 5)
          ]
        , Group [
             "title" := Scalar (String "Snow Crash")
           , "author" := Scalar (String "Neal Stephenson")
           , "price" := Scalar (Float 9.99)
           , "qty" := Scalar (Integer 8)
          ]
       ]
    , "misc" := Group [
          "pi" := Scalar (Float 3.141592654)
        , "bigint" := Scalar (Integer64 9223372036854775807)
        , "columns" := Array [
              String "Last Name"
            , String "First Name"
            , String MI
          ]
        , "bitmask" := Scalar (Integer 8131)
      ]
   ]
]

A note about the examples

To run these usage examples, you must tell GHC it's allowed to parse string literals as Text values:

>>> :set -XOverloadedStrings

Primitive types

data Setting Source

A libconfig Setting is a name-value pair, name := value.

Constructors

!Text := !Value infixr 3 

getSettingName :: Setting -> Text Source

Get out the name of a Setting

getSettingValue :: Setting -> Value Source

Get out the value of a Setting

data Value Source

A libconfig Value is either a Scalar value or some type of collection.

Constructors

Scalar !Scalar 
Array !Array 
List !List 
Group !Group 

isScalar :: Value -> Bool Source

>>> isScalar $ Scalar (String "butts")
True
>>> isScalar $ Array [String "butts"]
False

isCollection :: Value -> Bool Source

isCollection = not . isScalar
>>> isCollection $ Scalar (String "butts")
False
>>> isCollection $ Array [String "butts"]
True

isArray :: Value -> Bool Source

>>> isArray $ Array [String "butts"]
True
>>> isArray $ List [Scalar $ String "butts"]
False

isGroup :: Value -> Bool Source

>>> isGroup $ Array [String "butts"]
False
>>> isGroup $ Group ["asset" := Scalar (String "butts")]
True

isList :: Value -> Bool Source

>>> isList $ Array [String "butts"]
False
>>> isList $ List [Scalar $ String "butts"]
True

data Scalar Source

A libconfig Scalar value is a boolean value, a string or one of an assortment of numeric types.

Collection types

type Array = [Scalar] Source

libconfig Arrays can contain any number Scalar values.

type List = [Value] Source

libconfig Lists can contain any number of Values.

type Group = [Setting] Source

libconfig Groups are like Lists, except that each element in the Group is a Setting with its own unique name, not just an unlabeled Value.

Re-exports

data Text :: *

A space efficient, packed, unboxed Unicode text type.

Instances

IsList Text 
Eq Text 
Data Text

This instance preserves data abstraction at the cost of inefficiency. We omit reflection services for the sake of data abstraction.

This instance was created by copying the updated behavior of Data.Set.Set and Data.Map.Map. If you feel a mistake has been made, please feel free to submit improvements.

The original discussion is archived here: could we get a Data instance for Data.Text.Text?

The followup discussion that changed the behavior of Set and Map is archived here: Proposal: Allow gunfold for Data.Map, ...

Ord Text 
Read Text 
Show Text 
IsString Text 
Monoid Text 
Binary Text 
Serialize Text 
NFData Text 
Hashable Text 
Semigroup Text 
Typeable * Text 
type Item Text = Char