Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build issues #141

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 1 addition & 2 deletions src/Network/MPD/Commands/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ module Network.MPD.Commands.Parse where

import Network.MPD.Commands.Types

import Control.Monad
import Control.Monad.Except
import Control.Monad (foldM)
import Data.Maybe (fromMaybe)

import Network.MPD.Util
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
Loading