Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrt-x committed Jun 16, 2024
1 parent 1c8146a commit 88bf70d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/Network/MPD/Applicative/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ newtype Parser a
deriving Functor

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

instance Fail.MonadFail Parser where
fail = Prelude.fail

instance Applicative Parser where
pure = return
pure a = Parser $ \input -> Right (a, input)
(<*>) = ap

-- | Convert a regular parser.
Expand Down
14 changes: 7 additions & 7 deletions src/Network/MPD/Commands/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ toExpr (m:ms) = ExprAnd (Exact m) (toExpr ms)

instance Monoid Query where
mempty = Query []
Query a `mappend` Query b = Query (a ++ b)
Query [] `mappend` Filter b = Filter b
Filter a `mappend` Query [] = Filter a
Query a `mappend` Filter b = Filter (ExprAnd (toExpr a) b)
Filter a `mappend` Query b = Filter (ExprAnd a (toExpr b))
Filter a `mappend` Filter b = Filter (a <> b)

instance Semigroup Query where
(<>) = mappend
Query a <> Query b = Query (a ++ b)
Query [] <> Filter b = Filter b
Filter a <> Query [] = Filter a
Query a <> Filter b = Filter (ExprAnd (toExpr a) b)
Filter a <> Query b = Filter (ExprAnd a (toExpr b))
Filter a <> Filter b = Filter (a <> b)

instance Semigroup Expr where
ex1 <> ex2 = ExprAnd ex1 ex2

Expand Down
22 changes: 7 additions & 15 deletions src/Network/MPD/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Network.MPD.Core.Error
import Data.Char (isDigit)
import qualified Control.Exception as E
import Control.Exception.Safe (catch, catchAny)
import Control.Monad (ap, unless)
import Control.Monad (unless)
import Control.Monad.Except (ExceptT(..),runExceptT, MonadError(..))
import Control.Monad.Reader (ReaderT(..), ask)
import Control.Monad.State (StateT, MonadIO(..), modify, gets, evalStateT)
Expand All @@ -54,7 +54,6 @@ import System.IO.Error (isEOFError, tryIOError, ioeGetErrorType)
import Text.Printf (printf)
import qualified GHC.IO.Exception as GE

import qualified Prelude
import Prelude hiding (break, drop, dropWhile, read)
import Data.ByteString.Char8 (ByteString, isPrefixOf, break, drop, dropWhile)
import qualified Data.ByteString.Char8 as B
Expand Down Expand Up @@ -85,11 +84,7 @@ newtype MPD a =
MPD { runMPD :: ExceptT MPDError
(StateT MPDState
(ReaderT (Host, Port) IO)) a
} deriving (Functor, Monad, MonadIO, MonadError MPDError)

instance Applicative MPD where
(<*>) = ap
pure = return
} deriving (Functor, Applicative, Monad, MonadIO, MonadError MPDError)

instance MonadMPD MPD where
open = mpdOpen
Expand Down Expand Up @@ -140,10 +135,9 @@ mpdOpen = MPD $ do
`catchAny` const (return Nothing)
checkConn = do
singleMsg <- send ""
let [msg] = singleMsg
if "OK MPD" `isPrefixOf` msg
then MPD $ checkVersion $ parseVersion msg
else return False
case singleMsg of
[msg] | "OK MPD" `isPrefixOf` msg -> MPD $ checkVersion $ parseVersion msg
_ -> pure False

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

-- Consume response and return a Response.
parseResponse :: (MonadError MPDError m) => [ByteString] -> m [ByteString]
parseResponse xs
| null xs = throwError $ NoMPD
parseResponse [] = throwError $ NoMPD
parseResponse xs@(x : _)
| "ACK" `isPrefixOf` x = throwError $ parseAck x
| otherwise = return $ Prelude.takeWhile ("OK" /=) xs
where
x = head xs

-- Turn MPD ACK into the corresponding 'MPDError'
parseAck :: ByteString -> MPDError
Expand Down
1 change: 1 addition & 0 deletions tests/StringConn.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module StringConn where
import Control.Applicative
import Prelude hiding (exp)
import Control.Monad.Except
import Control.Monad
import Control.Monad.Identity
import Control.Monad.Reader
import Control.Monad.State
Expand Down

0 comments on commit 88bf70d

Please sign in to comment.