Some comments/docs

Ilya Portnov [2010-04-23 15:45:29]
Some comments/docs
Filename
Methods.hs
Network/YAML/WrapMethods.hs
Test.hs
TestCall.hs
TestTypes.hs
diff --git a/Methods.hs b/Methods.hs
index 99b71df..608c8c1 100644
--- a/Methods.hs
+++ b/Methods.hs
@@ -1,3 +1,4 @@
+-- | Testing RPC methods are defined here
 module Methods where

 import Control.Concurrent
diff --git a/Network/YAML/WrapMethods.hs b/Network/YAML/WrapMethods.hs
index 64bb22b..fb8d3f8 100644
--- a/Network/YAML/WrapMethods.hs
+++ b/Network/YAML/WrapMethods.hs
@@ -16,6 +16,10 @@ import Network.YAML.Derive
 import Network.YAML.Instances
 import Network.YAML.Dispatcher

+-- | Declare given function as remote method.
+-- This creates a function with same name as given (so qualified name must be
+-- used as argument), and almost same behaivour. Difference is that newly
+-- declared function takes pair (host name, port number) as first argument.
 remote :: Name -> Q [Dec]
 remote name = do
   srv <- newName "srv"
@@ -34,6 +38,9 @@ mkList :: [Exp] -> ExpQ
 mkList [] = [| [] |]
 mkList (e:es) = [| $(return e): $(mkList es) |]

+-- | Declare dispatching rules for given list of functions.
+-- Map with rules will be called dispatchingRules.
+-- For each given function RPC method with same name will be declared.
 declareRules :: [Name] -> Q [Dec]
 declareRules names = do
   pairs <- mapM rulePair names
diff --git a/Test.hs b/Test.hs
index a42a1cf..5672895 100644
--- a/Test.hs
+++ b/Test.hs
@@ -13,10 +13,12 @@ import Network.YAML.WrapMethods
 import TestTypes
 import Methods

+-- Declare dispatchingRules for given functions
 $(declareRules ['double, 'mySum, 'counter])

 main = do
   putStrLn "Listening..."
+  -- Start 3 listeners on 3 ports
   forkA [dispatcher 5000 dispatchingRules,
          dispatcher 5001 dispatchingRules,
          dispatcher 5002 dispatchingRules]
diff --git a/TestCall.hs b/TestCall.hs
index a7771c6..6beb7d8 100644
--- a/TestCall.hs
+++ b/TestCall.hs
@@ -12,6 +12,7 @@ import Network.YAML.WrapMethods
 import TestTypes
 import qualified Methods

+-- declare `double' and `mySum' as RPC methods
 $(remote 'Methods.double)
 $(remote 'Methods.mySum)

@@ -28,11 +29,13 @@ ps = [Point 3.0 5.0, Point 1.0 2.1, Point 0.1 0.2]
 main = do
   srv <- getService "test"

+  -- call remote functions
   r <- double srv p
   print r
   s <- mySum srv [3.5, 5.5, 1.0]
   print s

+  -- call remote functions for many arguments, for each argument on different server maybe
   rs <- callP getService "test" "double" ps
   print (rs :: [Point])
   cs <- callP getService "test" "counter" $ zip ([3,4,5,6] :: [Int]) ([1..] :: [Int])
diff --git a/TestTypes.hs b/TestTypes.hs
index 3d138f0..2f2c53d 100644
--- a/TestTypes.hs
+++ b/TestTypes.hs
@@ -1,4 +1,5 @@
 {-# LANGUAGE OverloadedStrings, TemplateHaskell, TypeSynonymInstances, MultiParamTypeClasses #-}
+-- | Declare types for using in test server and test client.
 module TestTypes where

 import Data.Default
@@ -8,7 +9,9 @@ import Network.YAML.Derive
 data Point = Point { x :: Double, y :: Double }
   deriving (Show)

+-- instance Default Point ...
 $(deriveDefault ''Point)

+-- instance IsYamlObject Point ...
 $(deriveIsYamlObject ''Point)
ViewGit