Add haddock documentation

This commit is contained in:
rnhmjoj 2016-05-05 18:06:20 +02:00
parent a1837d70fe
commit c32525c9ce
No known key found for this signature in database
GPG Key ID: 362BB82B7E496B7C
2 changed files with 14 additions and 5 deletions

View File

@ -1,3 +1,4 @@
-- | JSON utilities
module Json where module Json where
import Data.Aeson import Data.Aeson
@ -8,17 +9,19 @@ import Data.List (intercalate)
import qualified Data.Vector as V import qualified Data.Vector as V
import qualified Data.HashMap.Strict as H import qualified Data.HashMap.Strict as H
-- Get the JSON value of a key -- | Get the JSON value of a key
(|.) :: Object -> Text -> Value (|.) :: Object -> Text -> Value
obj |. key = case parse (.: key) obj of obj |. key = case parse (.: key) obj of
Success val -> val Success val -> val
Error err -> toJSON err Error err -> toJSON err
-- Get the String value of a key
-- | Get the String value of a key
(|:) :: Object -> Text -> String (|:) :: Object -> Text -> String
obj |: key = repr (obj |. key) obj |: key = repr (obj |. key)
-- Create a String representation of a JSON value
-- | Create a String representation of a 'Value'
repr :: Value -> String repr :: Value -> String
repr obj = repr' obj 0 where repr obj = repr' obj 0 where
repr' val lev = repr' val lev =
@ -34,6 +37,7 @@ repr obj = repr' obj 0 where
indent l = '\n' : (concat . replicate l) " " indent l = '\n' : (concat . replicate l) " "
dump o l k = concat [indent l, unpack k, ": ", repr' (o |. k) (l+1)] dump o l k = concat [indent l, unpack k, ": ", repr' (o |. k) (l+1)]
-- Pretty print a JSON value
-- | Pretty print a JSON 'Value'
pprint :: Value -> IO () pprint :: Value -> IO ()
pprint = putStrLn . repr pprint = putStrLn . repr

View File

@ -1,4 +1,6 @@
{-# LANGUAGE RecordWildCards, OverloadedStrings #-} {-# LANGUAGE RecordWildCards, OverloadedStrings #-}
-- | Main module
module Main where
import Json import Json
@ -56,6 +58,9 @@ description = info (helper <*> options)
<> footer "Stat rosa pristina nomine, nomina nuda tenemus." ) <> footer "Stat rosa pristina nomine, nomina nuda tenemus." )
-- * Program
-- | Main function -- | Main function
main :: IO () main :: IO ()
main = execParser description >>= exec where main = execParser description >>= exec where