summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.org3
-rw-r--r--krpc.cabal1
-rw-r--r--src/Remote/KRPC.hs49
3 files changed, 45 insertions, 8 deletions
diff --git a/TODO.org b/TODO.org
index fc8ad395..ddd2a846 100644
--- a/TODO.org
+++ b/TODO.org
@@ -8,7 +8,8 @@
8* DONE fix performance issues 8* DONE fix performance issues
9* DONE add readme 9* DONE add readme
10* DONE return scheme back 10* DONE return scheme back
11* TODO add show instance for method 11* DONE add Show instance for Method
12* TODO add BEncodable instance for Method
12* TODO hide async api 13* TODO hide async api
13* TODO expose client addr in server-side 14* TODO expose client addr in server-side
14* TODO major version bump (reason: exported type changed) 15* TODO major version bump (reason: exported type changed)
diff --git a/krpc.cabal b/krpc.cabal
index ab8d8f77..20553dee 100644
--- a/krpc.cabal
+++ b/krpc.cabal
@@ -32,6 +32,7 @@ source-repository head
32library 32library
33 default-language: Haskell2010 33 default-language: Haskell2010
34 default-extensions: PatternGuards 34 default-extensions: PatternGuards
35 , RecordWildCards
35 hs-source-dirs: src 36 hs-source-dirs: src
36 exposed-modules: Remote.KRPC 37 exposed-modules: Remote.KRPC
37 , Remote.KRPC.Protocol 38 , Remote.KRPC.Protocol
diff --git a/src/Remote/KRPC.hs b/src/Remote/KRPC.hs
index 485327e1..71faa3f3 100644
--- a/src/Remote/KRPC.hs
+++ b/src/Remote/KRPC.hs
@@ -84,12 +84,13 @@
84-- 84--
85-- For protocol details see 'Remote.KRPC.Protocol' module. 85-- For protocol details see 'Remote.KRPC.Protocol' module.
86-- 86--
87{-# LANGUAGE OverloadedStrings #-} 87{-# LANGUAGE OverloadedStrings #-}
88{-# LANGUAGE FlexibleContexts #-} 88{-# LANGUAGE ViewPatterns #-}
89{-# LANGUAGE DeriveDataTypeable #-} 89{-# LANGUAGE FlexibleContexts #-}
90{-# LANGUAGE ExplicitForAll #-} 90{-# LANGUAGE DeriveDataTypeable #-}
91{-# LANGUAGE KindSignatures #-} 91{-# LANGUAGE ExplicitForAll #-}
92{-# LANGUAGE ViewPatterns #-} 92{-# LANGUAGE KindSignatures #-}
93{-# LANGUAGE ScopedTypeVariables #-}
93module Remote.KRPC 94module Remote.KRPC
94 ( -- * Method 95 ( -- * Method
95 Method(..) 96 Method(..)
@@ -116,6 +117,7 @@ import Data.BEncode
116import Data.ByteString.Char8 as BC 117import Data.ByteString.Char8 as BC
117import Data.List as L 118import Data.List as L
118import Data.Map as M 119import Data.Map as M
120import Data.Monoid
119import Data.Typeable 121import Data.Typeable
120import Network 122import Network
121 123
@@ -154,7 +156,40 @@ data Method param result = Method {
154 , methodVals :: [ValName] 156 , methodVals :: [ValName]
155 } 157 }
156 158
157-- TODO ppMethod 159instance (Typeable a, Typeable b) => Show (Method a b) where
160 showsPrec _ = showsMethod
161
162showsMethod
163 :: forall a. forall b.
164 Typeable a => Typeable b
165 => Method a b -> ShowS
166showsMethod Method {..} =
167 showString (BC.unpack methodName) <>
168 showString " :: " <>
169 showsTuple methodParams paramsTy <>
170 showString " -> " <>
171 showsTuple methodVals valuesTy
172 where
173 paramsTy = typeOf (error "KRPC.showsMethod: impossible" :: a)
174 valuesTy = typeOf (error "KRPC.showsMethod: impossible" :: b)
175
176 showsTuple ns ty
177 = showChar '('
178 <> mconcat (L.intersperse (showString ", ") $
179 L.zipWith showsTyArgName ns (detuple ty))
180 <> showChar ')'
181
182 showsTyArgName ns ty
183 = showString (BC.unpack ns)
184 <> showString " :: "
185 <> showString (show ty)
186
187 detuple tyRep
188 | L.null args = [tyRep]
189 | otherwise = args
190 where
191 args = typeRepArgs tyRep
192
158 193
159-- | Identity procedure signature. Could be used for echo 194-- | Identity procedure signature. Could be used for echo
160-- servers. Implemented as: 195-- servers. Implemented as: