@@ -28,7 +28,7 @@ import Network.MPD.Core.Error
28
28
import Data.Char (isDigit )
29
29
import qualified Control.Exception as E
30
30
import Control.Exception.Safe (catch , catchAny )
31
- import Control.Monad (ap , unless )
31
+ import Control.Monad (unless )
32
32
import Control.Monad.Except (ExceptT (.. ),runExceptT , MonadError (.. ))
33
33
import Control.Monad.Reader (ReaderT (.. ), ask )
34
34
import Control.Monad.State (StateT , MonadIO (.. ), modify , gets , evalStateT )
@@ -54,7 +54,6 @@ import System.IO.Error (isEOFError, tryIOError, ioeGetErrorType)
54
54
import Text.Printf (printf )
55
55
import qualified GHC.IO.Exception as GE
56
56
57
- import qualified Prelude
58
57
import Prelude hiding (break , drop , dropWhile , read )
59
58
import Data.ByteString.Char8 (ByteString , isPrefixOf , break , drop , dropWhile )
60
59
import qualified Data.ByteString.Char8 as B
@@ -85,11 +84,7 @@ newtype MPD a =
85
84
MPD { runMPD :: ExceptT MPDError
86
85
(StateT MPDState
87
86
(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 )
93
88
94
89
instance MonadMPD MPD where
95
90
open = mpdOpen
@@ -140,10 +135,9 @@ mpdOpen = MPD $ do
140
135
`catchAny` const (return Nothing )
141
136
checkConn = do
142
137
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
147
141
148
142
checkVersion Nothing = throwError $ Custom " Couldn't determine MPD version"
149
143
checkVersion (Just version)
@@ -234,12 +228,10 @@ getResponse cmd = (send cmd >>= parseResponse) `catchError` sendpw
234
228
235
229
-- Consume response and return a Response.
236
230
parseResponse :: (MonadError MPDError m ) => [ByteString ] -> m [ByteString ]
237
- parseResponse xs
238
- | null xs = throwError $ NoMPD
231
+ parseResponse [] = throwError $ NoMPD
232
+ parseResponse xs @ (x : _)
239
233
| " ACK" `isPrefixOf` x = throwError $ parseAck x
240
234
| otherwise = return $ Prelude. takeWhile (" OK" /= ) xs
241
- where
242
- x = head xs
243
235
244
236
-- Turn MPD ACK into the corresponding 'MPDError'
245
237
parseAck :: ByteString -> MPDError
0 commit comments