diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-24 06:28:23 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-24 06:28:23 +0400 |
commit | 10829a428735d034f927e45561dcf94703cd376a (patch) | |
tree | 9b6a285060f80f2ac55e7935cd99fe52f43b8cff /src | |
parent | 257844fe956a4736feca82bc3e802a09fcc0977a (diff) |
Update documentation in Method module
Diffstat (limited to 'src')
-rw-r--r-- | src/Network/KRPC/Method.hs | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/Network/KRPC/Method.hs b/src/Network/KRPC/Method.hs index f4392f35..f70923f5 100644 --- a/src/Network/KRPC/Method.hs +++ b/src/Network/KRPC/Method.hs | |||
@@ -1,3 +1,12 @@ | |||
1 | -- | | ||
2 | -- Copyright : (c) Sam Truzjan 2013 | ||
3 | -- License : BSD3 | ||
4 | -- Maintainer : pxqr.sta@gmail.com | ||
5 | -- Stability : experimental | ||
6 | -- Portability : portable | ||
7 | -- | ||
8 | -- Normally, you don't need to import this module. | ||
9 | -- | ||
1 | {-# LANGUAGE RankNTypes #-} | 10 | {-# LANGUAGE RankNTypes #-} |
2 | {-# LANGUAGE MultiParamTypeClasses #-} | 11 | {-# LANGUAGE MultiParamTypeClasses #-} |
3 | {-# LANGUAGE FunctionalDependencies #-} | 12 | {-# LANGUAGE FunctionalDependencies #-} |
@@ -10,6 +19,7 @@ module Network.KRPC.Method | |||
10 | ) where | 19 | ) where |
11 | 20 | ||
12 | import Data.BEncode (BEncode) | 21 | import Data.BEncode (BEncode) |
22 | import Data.ByteString.Char8 as BC | ||
13 | import Data.Char | 23 | import Data.Char |
14 | import Data.Monoid | 24 | import Data.Monoid |
15 | import Data.List as L | 25 | import Data.List as L |
@@ -18,31 +28,30 @@ import Data.Typeable | |||
18 | import Network.KRPC.Message | 28 | import Network.KRPC.Message |
19 | 29 | ||
20 | 30 | ||
21 | -- | Method datatype used to describe name, parameters and return | 31 | -- | Method datatype used to describe method name, parameters and |
22 | -- values of procedure. Client use a method to /invoke/, server | 32 | -- return values of procedure. Client use a method to /invoke/, server |
23 | -- /implements/ the method to make the actual work. | 33 | -- /implements/ the method to make the actual work. |
24 | -- | 34 | -- |
25 | -- We use the following fantom types to ensure type-safiety: | 35 | -- We use the following fantom types to ensure type-safiety: |
26 | -- | 36 | -- |
27 | -- * param: Type of method parameters. Ordinary Tuple type used | 37 | -- * param: Type of method parameters. |
28 | -- to specify more than one parameter, so for example @Method | ||
29 | -- (Int, Int) result@ will take two arguments. | ||
30 | -- | 38 | -- |
31 | -- * result: Type of return value of the method. Similarly, | 39 | -- * result: Type of return value of the method. |
32 | -- tuple used to specify more than one return value, so for | ||
33 | -- exsample @Method (Foo, Bar) (Bar, Foo)@ will take two arguments | ||
34 | -- and return two values. | ||
35 | -- | 40 | -- |
36 | newtype Method param result = Method MethodName | 41 | newtype Method param result = Method MethodName |
37 | deriving (Eq, Ord, IsString, BEncode) | 42 | deriving (Eq, Ord, IsString, BEncode) |
38 | 43 | ||
44 | -- | Example: | ||
45 | -- | ||
46 | -- @show (Method \"concat\" :: [Int] Int) == \"concat :: [Int] -> Int\"@ | ||
47 | -- | ||
39 | instance (Typeable a, Typeable b) => Show (Method a b) where | 48 | instance (Typeable a, Typeable b) => Show (Method a b) where |
40 | showsPrec _ = showsMethod | 49 | showsPrec _ = showsMethod |
41 | 50 | ||
42 | showsMethod :: forall a. forall b. Typeable a => Typeable b | 51 | showsMethod :: forall a. forall b. Typeable a => Typeable b |
43 | => Method a b -> ShowS | 52 | => Method a b -> ShowS |
44 | showsMethod (Method name) = | 53 | showsMethod (Method name) = |
45 | shows name <> | 54 | showString (BC.unpack name) <> |
46 | showString " :: " <> | 55 | showString " :: " <> |
47 | shows paramsTy <> | 56 | shows paramsTy <> |
48 | showString " -> " <> | 57 | showString " -> " <> |
@@ -52,15 +61,23 @@ showsMethod (Method name) = | |||
52 | paramsTy = typeOf (impossible :: a) | 61 | paramsTy = typeOf (impossible :: a) |
53 | valuesTy = typeOf (impossible :: b) | 62 | valuesTy = typeOf (impossible :: b) |
54 | 63 | ||
55 | -- | Example: | 64 | -- | In order to perform or handle KRPC query you need to provide |
65 | -- corresponding 'KRPC' class. | ||
66 | -- | ||
67 | -- Example: | ||
68 | -- | ||
56 | -- @ | 69 | -- @ |
57 | -- data Ping = Ping Text deriving BEncode | 70 | -- data Ping = Ping Text deriving BEncode |
58 | -- data Pong = Pong Text deriving BEncode | 71 | -- data Pong = Pong Text deriving BEncode |
59 | -- | 72 | -- |
60 | -- instance KRPC Ping Pong where | 73 | -- instance 'KRPC' Ping Pong where |
61 | -- method = "ping" | 74 | -- method = \"ping\" |
62 | -- @ | 75 | -- @ |
76 | -- | ||
63 | class (BEncode req, BEncode resp) => KRPC req resp | req -> resp where | 77 | class (BEncode req, BEncode resp) => KRPC req resp | req -> resp where |
78 | -- | Method name. Default implementation uses lowercased @req@ | ||
79 | -- datatype name. | ||
80 | -- | ||
64 | method :: Method req resp | 81 | method :: Method req resp |
65 | 82 | ||
66 | -- TODO add underscores | 83 | -- TODO add underscores |