Created
February 16, 2015 10:59
-
-
Save qnikst/ce972188e7b8d10b0cec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE DefaultSignatures #-} | |
module TaggedPut where | |
import Data.Binary (Binary) | |
import qualified Data.Binary as Binary | |
import Data.ByteString.Lazy | |
data Binary' | |
newtype Protocol a = Protocol { getByteString :: ByteString } | |
getBinaryByteString :: Protocol Binary' -> ByteString | |
getBinaryByteString = getByteString | |
class TaggedPut p a where | |
put :: a -> Protocol p | |
default put :: TaggedPut Binary' a => a -> Protocol p | |
put = Protocol . getBinaryByteString . put | |
instance Binary a => TaggedPut Binary' a where | |
put = Protocol . Binary.encode | |
data Compact | |
instance TaggedPut Compact String | |
instance TaggedPut Compact Int where | |
put _ = Protocol (singleton 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment