summaryrefslogtreecommitdiff
path: root/src/Remote/KRPC.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Remote/KRPC.hs')
-rw-r--r--src/Remote/KRPC.hs49
1 files changed, 42 insertions, 7 deletions
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: