diff options
-rw-r--r-- | TODO.org | 3 | ||||
-rw-r--r-- | krpc.cabal | 1 | ||||
-rw-r--r-- | src/Remote/KRPC.hs | 49 |
3 files changed, 45 insertions, 8 deletions
@@ -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) |
@@ -32,6 +32,7 @@ source-repository head | |||
32 | library | 32 | library |
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 #-} | ||
93 | module Remote.KRPC | 94 | module Remote.KRPC |
94 | ( -- * Method | 95 | ( -- * Method |
95 | Method(..) | 96 | Method(..) |
@@ -116,6 +117,7 @@ import Data.BEncode | |||
116 | import Data.ByteString.Char8 as BC | 117 | import Data.ByteString.Char8 as BC |
117 | import Data.List as L | 118 | import Data.List as L |
118 | import Data.Map as M | 119 | import Data.Map as M |
120 | import Data.Monoid | ||
119 | import Data.Typeable | 121 | import Data.Typeable |
120 | import Network | 122 | import 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 | 159 | instance (Typeable a, Typeable b) => Show (Method a b) where |
160 | showsPrec _ = showsMethod | ||
161 | |||
162 | showsMethod | ||
163 | :: forall a. forall b. | ||
164 | Typeable a => Typeable b | ||
165 | => Method a b -> ShowS | ||
166 | showsMethod 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: |