@@ -28,7 +28,7 @@ import Network.MPD.Core.Error
2828import Data.Char (isDigit )
2929import qualified Control.Exception as E
3030import Control.Exception.Safe (catch , catchAny )
31- import Control.Monad (ap , unless )
31+ import Control.Monad (unless )
3232import Control.Monad.Except (ExceptT (.. ),runExceptT , MonadError (.. ))
3333import Control.Monad.Reader (ReaderT (.. ), ask )
3434import Control.Monad.State (StateT , MonadIO (.. ), modify , gets , evalStateT )
@@ -54,7 +54,6 @@ import System.IO.Error (isEOFError, tryIOError, ioeGetErrorType)
5454import Text.Printf (printf )
5555import qualified GHC.IO.Exception as GE
5656
57- import qualified Prelude
5857import Prelude hiding (break , drop , dropWhile , read )
5958import Data.ByteString.Char8 (ByteString , isPrefixOf , break , drop , dropWhile )
6059import 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
9489instance 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.
236230parseResponse :: (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'
245237parseAck :: ByteString -> MPDError
0 commit comments