Skip to content

Commit 88bf70d

Browse files
committed
Fix warnings
1 parent 1c8146a commit 88bf70d

File tree

4 files changed

+16
-24
lines changed

4 files changed

+16
-24
lines changed

src/Network/MPD/Applicative/Internal.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ newtype Parser a
4545
deriving Functor
4646

4747
instance Monad Parser where
48-
return a = Parser $ \input -> Right (a, input)
4948
p1 >>= p2 = Parser $ \input -> runParser p1 input >>= uncurry (runParser . p2)
5049

5150
instance Fail.MonadFail Parser where
5251
fail = Prelude.fail
5352

5453
instance Applicative Parser where
55-
pure = return
54+
pure a = Parser $ \input -> Right (a, input)
5655
(<*>) = ap
5756

5857
-- | Convert a regular parser.

src/Network/MPD/Commands/Query.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ toExpr (m:ms) = ExprAnd (Exact m) (toExpr ms)
7777

7878
instance Monoid Query where
7979
mempty = Query []
80-
Query a `mappend` Query b = Query (a ++ b)
81-
Query [] `mappend` Filter b = Filter b
82-
Filter a `mappend` Query [] = Filter a
83-
Query a `mappend` Filter b = Filter (ExprAnd (toExpr a) b)
84-
Filter a `mappend` Query b = Filter (ExprAnd a (toExpr b))
85-
Filter a `mappend` Filter b = Filter (a <> b)
8680

8781
instance Semigroup Query where
88-
(<>) = mappend
82+
Query a <> Query b = Query (a ++ b)
83+
Query [] <> Filter b = Filter b
84+
Filter a <> Query [] = Filter a
85+
Query a <> Filter b = Filter (ExprAnd (toExpr a) b)
86+
Filter a <> Query b = Filter (ExprAnd a (toExpr b))
87+
Filter a <> Filter b = Filter (a <> b)
88+
8989
instance Semigroup Expr where
9090
ex1 <> ex2 = ExprAnd ex1 ex2
9191

src/Network/MPD/Core.hs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import Network.MPD.Core.Error
2828
import Data.Char (isDigit)
2929
import qualified Control.Exception as E
3030
import Control.Exception.Safe (catch, catchAny)
31-
import Control.Monad (ap, unless)
31+
import Control.Monad (unless)
3232
import Control.Monad.Except (ExceptT(..),runExceptT, MonadError(..))
3333
import Control.Monad.Reader (ReaderT(..), ask)
3434
import Control.Monad.State (StateT, MonadIO(..), modify, gets, evalStateT)
@@ -54,7 +54,6 @@ import System.IO.Error (isEOFError, tryIOError, ioeGetErrorType)
5454
import Text.Printf (printf)
5555
import qualified GHC.IO.Exception as GE
5656

57-
import qualified Prelude
5857
import Prelude hiding (break, drop, dropWhile, read)
5958
import Data.ByteString.Char8 (ByteString, isPrefixOf, break, drop, dropWhile)
6059
import qualified Data.ByteString.Char8 as B
@@ -85,11 +84,7 @@ newtype MPD a =
8584
MPD { runMPD :: ExceptT MPDError
8685
(StateT MPDState
8786
(ReaderT (Host, Port) IO)) a
88-
} deriving (Functor, Monad, MonadIO, MonadError MPDError)
89-
90-
instance Applicative MPD where
91-
(<*>) = ap
92-
pure = return
87+
} deriving (Functor, Applicative, Monad, MonadIO, MonadError MPDError)
9388

9489
instance MonadMPD MPD where
9590
open = mpdOpen
@@ -140,10 +135,9 @@ mpdOpen = MPD $ do
140135
`catchAny` const (return Nothing)
141136
checkConn = do
142137
singleMsg <- send ""
143-
let [msg] = singleMsg
144-
if "OK MPD" `isPrefixOf` msg
145-
then MPD $ checkVersion $ parseVersion msg
146-
else return False
138+
case singleMsg of
139+
[msg] | "OK MPD" `isPrefixOf` msg -> MPD $ checkVersion $ parseVersion msg
140+
_ -> pure False
147141

148142
checkVersion Nothing = throwError $ Custom "Couldn't determine MPD version"
149143
checkVersion (Just version)
@@ -234,12 +228,10 @@ getResponse cmd = (send cmd >>= parseResponse) `catchError` sendpw
234228

235229
-- Consume response and return a Response.
236230
parseResponse :: (MonadError MPDError m) => [ByteString] -> m [ByteString]
237-
parseResponse xs
238-
| null xs = throwError $ NoMPD
231+
parseResponse [] = throwError $ NoMPD
232+
parseResponse xs@(x : _)
239233
| "ACK" `isPrefixOf` x = throwError $ parseAck x
240234
| otherwise = return $ Prelude.takeWhile ("OK" /=) xs
241-
where
242-
x = head xs
243235

244236
-- Turn MPD ACK into the corresponding 'MPDError'
245237
parseAck :: ByteString -> MPDError

tests/StringConn.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module StringConn where
1414
import Control.Applicative
1515
import Prelude hiding (exp)
1616
import Control.Monad.Except
17+
import Control.Monad
1718
import Control.Monad.Identity
1819
import Control.Monad.Reader
1920
import Control.Monad.State

0 commit comments

Comments
 (0)