on master help sign in
Some HLint suggestions

Conflicts: Data/Yaml/Internal.hs

commit53f4cf3f4a5ed01a50ce0609a70abd30b248a219 authorMatej Kollar <208115@mail.muni.cz> dateSun 6 Sep 2015, 11:43 (11 years ago) parent4beaa8b
5 files changed+17−19
Data/Yaml.hs+7−7 Data/Yaml/Builder.hs+1−1 Data/Yaml/Internal.hs+4−6 Data/Yaml/Pretty.hs+2−1 exe/json2yaml.hs+3−4
Data/Yaml.hs+7−7
@@ -1,5 +1,4 @@
11{-# LANGUAGE CPP #-}
2−{-# LANGUAGE PatternGuards #-}
32{-# LANGUAGE ScopedTypeVariables #-}
43{-# LANGUAGE OverloadedStrings #-}
54-- | Provides a high-level interface for processing YAML files.
@@ -76,6 +75,7 @@ import qualified Data.Text.Lazy as TL
7675import Data.Text.Lazy.Builder (toLazyText)
7776import Data.Aeson.Encode (encodeToTextBuilder)
7877import Control.Monad.Trans.Resource (runResourceT)
78+import Control.Applicative((<$>))
7979
8080import Data.Yaml.Internal
8181
@@ -106,10 +106,10 @@ objToEvents' :: Value -> [Y.Event] -> [Y.Event]
106106--objToEvents' (Scalar s) rest = scalarToEvent s : rest
107107objToEvents' (Array list) rest =
108108 EventSequenceStart Nothing
109− : foldr ($) (EventSequenceEnd : rest) (map objToEvents' $ V.toList list)
109+ : foldr objToEvents' (EventSequenceEnd : rest) (V.toList list)
110110objToEvents' (Object pairs) rest =
111111 EventMappingStart Nothing
112− : foldr ($) (EventMappingEnd : rest) (map pairToEvents $ M.toList pairs)
112+ : foldr pairToEvents (EventMappingEnd : rest) (M.toList pairs)
113113
114114-- Empty strings need special handling to ensure they get quoted. This avoids:
115115-- https://github.com/snoyberg/yaml/issues/24
@@ -138,8 +138,8 @@ decode :: FromJSON a
138138 => ByteString
139139 -> Maybe a
140140decode bs = unsafePerformIO
141− $ fmap (either (const Nothing) id)
142− $ decodeHelper_ (Y.decode bs)
141+ $ either (const Nothing) id
142+ <$> decodeHelper_ (Y.decode bs)
143143
144144decodeFile :: FromJSON a
145145 => FilePath
@@ -157,8 +157,8 @@ decodeFileEither = decodeHelper_ . Y.decodeFile
157157
158158decodeEither :: FromJSON a => ByteString -> Either String a
159159decodeEither bs = unsafePerformIO
160− $ fmap (either (Left . prettyPrintParseException) id)
161− $ decodeHelper (Y.decode bs)
160+ $ either (Left . prettyPrintParseException) id
161+ <$> decodeHelper (Y.decode bs)
162162
163163-- | More helpful version of 'decodeEither' which returns the 'YamlException'.
164164--
Data/Yaml/Builder.hs+1−1
@@ -67,7 +67,7 @@ array :: [YamlBuilder] -> YamlBuilder
6767array bs =
6868 YamlBuilder $ (EventSequenceStart Nothing:) . flip (foldr go) bs . (EventSequenceEnd:)
6969 where
70− go (YamlBuilder b) rest = b rest
70+ go (YamlBuilder b) = b
7171
7272string :: Text -> YamlBuilder
7373-- Empty strings need special handling to ensure they get quoted. This avoids:
Data/Yaml/Internal.hs+4−6
@@ -26,9 +26,9 @@ import qualified Data.Conduit as C
2626import qualified Data.Conduit.List as CL
2727import Control.Monad.Trans.Class (MonadTrans, lift)
2828import Control.Monad.IO.Class (MonadIO, liftIO)
29−import Control.Monad (liftM, ap)
29+import Control.Monad (liftM, ap, unless)
3030#if !MIN_VERSION_base(4,8,0)
31−import Control.Applicative (Applicative(..))
31+import Control.Applicative ((<$>), Applicative(..))
3232#endif
3333import Data.Char (toUpper)
3434import qualified Data.Vector as V
@@ -126,9 +126,7 @@ type Parse = StateT (Map.Map String Value) (ResourceT IO)
126126requireEvent :: Event -> C.Sink Event Parse ()
127127requireEvent e = do
128128 f <- CL.head
129− if f == Just e
130− then return ()
131− else liftIO $ throwIO $ UnexpectedEvent f $ Just e
129+ unless (f == Just e) $ liftIO $ throwIO $ UnexpectedEvent f $ Just e
132130
133131parse :: C.Sink Event Parse Value
134132parse = do
@@ -170,7 +168,7 @@ parseO :: C.Sink Event Parse Value
170168parseO = do
171169 me <- CL.head
172170 case me of
173− Just (EventScalar v tag style a) -> fmap (textToValue style tag) $ parseScalar v a style tag
171+ Just (EventScalar v tag style a) -> textToValue style tag <$> parseScalar v a style tag
174172 Just (EventSequenceStart a) -> parseS a id
175173 Just (EventMappingStart a) -> parseM a M.empty
176174 Just (EventAlias an) -> do
Data/Yaml/Pretty.hs+2−1
@@ -9,6 +9,7 @@ module Data.Yaml.Pretty
99 , defConfig
1010 ) where
1111
12+import Control.Applicative ((<$>))
1213import Data.Yaml.Builder
1314import Data.Aeson.Types
1415import Data.Text (Text)
@@ -45,7 +46,7 @@ setConfCompare cmp c = c { confCompare = cmp }
4546pretty :: Config -> Value -> YamlBuilder
4647pretty cfg = go
4748 where go (Object o) = mapping (sortBy (confCompare cfg `on` fst) $ HM.toList $ HM.map go o)
48− go (Array a) = array (fmap go $ V.toList a)
49+ go (Array a) = array (go <$> V.toList a)
4950 go Null = null
5051 go (String s) = string s
5152 go (Number n) = scientific n
exe/json2yaml.hs+3−4
@@ -18,7 +18,6 @@ main = do
1818 _ -> L.readFile input
1919 case mval of
2020 Nothing -> error "Invalid input JSON"
21− Just val -> do
22− case output of
23− "-" -> S.putStr $ Y.encode (val :: Y.Value)
24− _ -> Y.encodeFile output val
21+ Just val -> case output of
22+ "-" -> S.putStr $ Y.encode (val :: Y.Value)
23+ _ -> Y.encodeFile output val