| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
KDL.Arrow
Contents
Description
This module defines the Arrow interface for decoding a KDL document. Intended to be imported qualified as:
import KDL.Arrow qualified as KDL
For most use-cases, the Monad interface exported by KDL is sufficient. You may wish to use the Arrow interface if you would like to statically analyze a decoder's schema, e.g. to generate documentation.
Quickstart
Given a file config.kdl:
package {
name my-pkg
version "1.2.3"
dependencies {
aeson ">= 2.2.3.0" optional=#true
text ">= 2"
}
}
Parse it with:
{-# LANGUAGE Arrows #-}
import KDL.Arrow qualified as KDL
main :: IO ()
main = do
config <- KDL.decodeFileWith decoder "config.kdl"
print config
decoder :: KDL.DocumentDecoder Config
decoder = KDL.document $ proc () -> do
KDL.node "package" -< ()
data Config = Config
{ name :: Text
, version :: Text
, dependencies :: Map Text Dep
}
deriving (Show)
data Dep = Dep
{ version :: Text
, optional :: Bool
}
deriving (Show)
instance KDL.DecodeNode Config where
nodeDecoder = proc () -> do
name <- KDL.argAt "name" -< ()
version <- KDL.argAt "version" -< ()
dependencies <- KDL.nodeWith "dependencies" . KDL.children $ KDL.remainingNodes -< ()
returnA -< Config{..}
instance KDL.DecodeNode Dep where
nodeDecoder = proc () -> do
version <- KDL.arg -< ()
optional <- KDL.option False $ KDL.prop "optional" -< ()
returnA -< Dep{..}
Synopsis
- module KDL.Decoder.Arrow
- module KDL.Decoder.Schema
- module KDL.Parser
- module KDL.Render
- module KDL.Types
- module Control.Arrow
- module Control.Category
KDL re-exports
module KDL.Decoder.Arrow
module KDL.Decoder.Schema
module KDL.Parser
module KDL.Render
module KDL.Types
base re-reexports
module Control.Arrow
module Control.Category