summaryrefslogtreecommitdiff
path: root/src/Remote/KRPC
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-05-11 21:31:05 +0400
committerSam T <pxqr.sta@gmail.com>2013-05-11 21:31:05 +0400
commit3806b3513f04dd360badf438fa103334dd32933c (patch)
tree28eeb1f784a218fd179ea6d4e1a9ce73ad7cbdef /src/Remote/KRPC
parent96c554f6ab63e6e207d0c7e65d3ef1cdef7baa9c (diff)
~ Separate method implementation.
This will break everything for now.
Diffstat (limited to 'src/Remote/KRPC')
-rw-r--r--src/Remote/KRPC/Method.hs47
1 files changed, 22 insertions, 25 deletions
diff --git a/src/Remote/KRPC/Method.hs b/src/Remote/KRPC/Method.hs
index f4b0bb9a..3c757d07 100644
--- a/src/Remote/KRPC/Method.hs
+++ b/src/Remote/KRPC/Method.hs
@@ -1,12 +1,12 @@
1{-# LANGUAGE OverloadedStrings #-} 1{-# LANGUAGE OverloadedStrings #-}
2module Remote.KRPC.Method 2module Remote.KRPC.Method
3 ( Method(methodName, methodParams, methodVals, methodBody) 3 ( Method(methodName, methodParams, methodVals)
4 4
5 -- * Construction 5 -- * Construction
6 , method 6 , method
7 7
8 -- * Predefined methods 8 -- * Predefined methods
9 , idM, composeM, concatM 9 , idM, composeM
10 ) where 10 ) where
11 11
12import Prelude hiding ((.), id) 12import Prelude hiding ((.), id)
@@ -15,6 +15,8 @@ import Control.Monad
15 15
16import Remote.KRPC.Protocol 16import Remote.KRPC.Protocol
17 17
18
19
18-- | The 20-- | The
19-- 21--
20-- * argument: type of method parameter 22-- * argument: type of method parameter
@@ -23,30 +25,35 @@ import Remote.KRPC.Protocol
23-- 25--
24-- * result: type of return value of the method. 26-- * result: type of return value of the method.
25-- 27--
26data Method remote param result = Method { 28data Method param result = Method {
27 -- | Name used in query and 29 -- | Name used in query and
28 methodName :: [MethodName] 30 methodName :: [MethodName]
29 31
30 -- | Description of each method parameter in right to left order. 32 -- | Description of each parameter in /right to left/ order.
31 , methodParams :: [ParamName] 33 , methodParams :: [ParamName]
32 34
33 -- | Description of each method return value in right to left order. 35 -- | Description of each return value in /right to left/ order.
34 , methodVals :: [ValName] 36 , methodVals :: [ValName]
35
36 -- | Description of method body.
37 , methodBody :: param -> remote result
38 } 37 }
39 38
40instance Monad remote => Category (Method remote) where 39instance Category Method where
40 {-# SPECIALIZE instance Category Method #-}
41 id = idM 41 id = idM
42 {-# INLINE id #-}
43
42 (.) = composeM 44 (.) = composeM
45 {-# INLINE (.) #-}
46
47
48-- TODO ppMethod
43 49
44-- | Remote identity function. Could be used for echo servers for example. 50-- | Remote identity function. Could be used for echo servers for example.
45-- 51--
46-- idM = method "id" ["x"] ["y"] return 52-- idM = method "id" ["x"] ["y"] return
47-- 53--
48idM :: Monad m => Method m a a 54idM :: Method a a
49idM = method "id" ["x"] ["y"] return 55idM = method "id" ["x"] ["y"]
56{-# INLINE idM #-}
50 57
51-- | Pipelining of two or more methods. 58-- | Pipelining of two or more methods.
52-- 59--
@@ -54,23 +61,13 @@ idM = method "id" ["x"] ["y"] return
54-- KRPC, so both server and client should use this implementation, 61-- KRPC, so both server and client should use this implementation,
55-- otherwise you more likely get the 'ProtocolError'. 62-- otherwise you more likely get the 'ProtocolError'.
56-- 63--
57composeM :: Monad m => Method m b c -> Method m a b -> Method m a c 64composeM :: Method b c -> Method a b -> Method a c
58composeM g h = Method (methodName g ++ methodName h) 65composeM g h = Method (methodName g ++ methodName h)
59 (methodParams h) 66 (methodParams h)
60 (methodVals g) 67 (methodVals g)
61 (methodBody h >=> methodBody g) 68{-# INLINE composeM #-}
62
63-- | Concat list of list. Could be used for performance tests.
64--
65-- concatM = method "concat" ["xxs"] ["xs"] $ return . Prelude.concat
66--
67concatM :: Monad m => Method m [[a]] [a]
68concatM = method "concat" ["xxs"] ["xs"] $ return . Prelude.concat
69 69
70 70
71method :: MethodName 71method :: MethodName -> [ParamName] -> [ValName] -> Method param result
72 -> [ParamName]
73 -> [ValName]
74 -> (param -> remote result)
75 -> Method remote param result
76method name = Method [name] 72method name = Method [name]
73{-# INLINE method #-} \ No newline at end of file