Copyright | (c) Matthew Peddie 2014 |
---|---|
License | BSD3 |
Maintainer | mpeddie@gmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Core types for configuration file data.
- data Setting = !Text := !Value
- getSettingName :: Setting -> Text
- getSettingValue :: Setting -> Value
- data Value
- isScalar :: Value -> Bool
- isCollection :: Value -> Bool
- isArray :: Value -> Bool
- isGroup :: Value -> Bool
- isList :: Value -> Bool
- data Scalar
- type Array = [Scalar]
- type List = [Value]
- type Group = [Setting]
- data Int32 :: *
- data Int64 :: *
- data Word32 :: *
- data Word64 :: *
- data Text :: *
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
A libconfig
Setting
is a name-value pair, name := value
.
getSettingName :: Setting -> Text Source
Get out the name of a Setting
getSettingValue :: Setting -> Value Source
Get out the value of a Setting
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
A libconfig Scalar
value is a boolean value, a string or one of
an assortment of numeric types.
Collection types
Re-exports
data Int32 :: *
32-bit signed integer type
data Int64 :: *
64-bit signed integer type
data Word32 :: *
32-bit unsigned integer type
data Word64 :: *
64-bit unsigned integer type
data Text :: *
A space efficient, packed, unboxed Unicode text type.
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
The original discussion is archived here: could we get a Data instance for Data.Text.Text? The followup discussion that changed the behavior of |
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 |