Skip to content

Instantly share code, notes, and snippets.

@qnikst
Created February 16, 2015 10:59
Show Gist options
  • Save qnikst/ce972188e7b8d10b0cec to your computer and use it in GitHub Desktop.
Save qnikst/ce972188e7b8d10b0cec to your computer and use it in GitHub Desktop.
{-# 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