Skip to content

Commit

Permalink
Pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
honza committed Sep 3, 2015
1 parent 120597d commit 3dd4cc5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import qualified Data.ByteString as S
version :: ByteString
version = "0.5.0"

type Key = ByteString
type Key = ByteString
type Value = ByteString
type DB = Map Key Value
type DB = Map Key Value

data Command = Get Key
| Set Key Value
Expand All @@ -27,9 +27,11 @@ data Reply = Bulk (Maybe ByteString)
deriving (Eq, Show)

parseReply :: Reply -> Maybe Command
parseReply (MultiBulk (Just [Bulk (Just "get"), Bulk (Just a)])) = Just $ Get a
parseReply (MultiBulk (Just [Bulk (Just "set"), Bulk (Just a), Bulk (Just b)])) = Just $ Set a b
parseReply (MultiBulk _) = Just Unknown
parseReply (MultiBulk (Just xs)) =
case xs of
[Bulk (Just "get"), Bulk (Just a)] -> Just $ Get a
[Bulk (Just "set"), Bulk (Just a), Bulk (Just b)] -> Just $ Set a b
_ -> Just Unknown
parseReply _ = Nothing

replyParser :: Parser Reply
Expand Down

0 comments on commit 3dd4cc5

Please sign in to comment.