on master help sign in
Update yaml2json.hs

removed the unnecessary flag {-# LANGUAGE ScopedTypeVariables #-} simplified the args processing added type signature for showJSON

commit85c2339e6563d5b9b27e783cb84a26804ed6803c authorRay Qiu <ray.qiu@gmail.com> dateSat 6 Dec 2014, 22:06 (12 years ago) parent96d77a7
1 file changed+5−7
exe/yaml2json.hs+5−7
exe/yaml2json.hs+5−7
@@ -1,5 +1,3 @@
1−{-# LANGUAGE ScopedTypeVariables #-}
2−
31import Data.Yaml (decodeFileEither, decodeEither')
42import System.Environment (getArgs)
53import System.Exit
@@ -11,18 +9,18 @@ import Data.ByteString (getContents)
119helpMessage :: IO ()
1210helpMessage = putStrLn "yaml2json FILE\n use - as FILE to indicate stdin" >> exitFailure
1311
12+showJSON :: Show a => Either a Value -> IO b
1413showJSON ejson =
1514 case ejson of
1615 Left err -> print err >> exitFailure
17− Right (res :: Value) -> putStr (encode res) >> exitSuccess
16+ Right res -> putStr (encode (res :: Value)) >> exitSuccess
1817
1918main :: IO ()
2019main = do
2120 args <- getArgs
2221 case args of
23− [] -> helpMessage
24− (f:a:_) -> helpMessage
2522 -- strict getContents will read in all of stdin at once
26− ("-":[]) -> getContents >>= showJSON . decodeEither'
27− (f:[]) -> decodeFileEither f >>= showJSON
23+ (["-"]) -> getContents >>= showJSON . decodeEither'
24+ ([f]) -> decodeFileEither f >>= showJSON
25+ _ -> helpMessage
2826