From 48a364104cd9a63ab201cfa9f07955c3a1ef2715 Mon Sep 17 00:00:00 2001 From: Ilya Portnov Date: Sun, 30 May 2010 17:34:18 +0600 Subject: [PATCH] Simplify examples. --- Methods.hs | 18 +++++++++--------- Test.hs | 5 +---- TestCall.hs | 11 ++++------- TestTypes.hs | 2 -- 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Methods.hs b/Methods.hs index febb46b..9c9d11d 100644 --- a/Methods.hs +++ b/Methods.hs @@ -9,16 +9,16 @@ import Codec.Binary.UTF8.String import TestTypes -double :: State -> Point -> IO Point -double s (Point x y) = do - print s +double :: Point -> IO Point +double (Point x y) = do + print "test" return $ Point (x*2) (y*2) -mySum :: State -> [Double] -> IO Double -mySum s lst = return $ sum lst +mySum :: [Double] -> IO Double +mySum lst = return $ sum lst -counter :: State -> (Int,Int) -> IO Int -counter s (k,d) = do +counter :: (Int,Int) -> IO Int +counter (k,d) = do mapM count [k..k+10] return (k+10) where @@ -26,8 +26,8 @@ counter s (k,d) = do putStrLn $ show d ++ ": " ++ show i threadDelay (d*100000) -ls :: State -> String -> IO [String] -ls s path = do +ls :: String -> IO [String] +ls path = do let path' = encodeString path lst <- getDirectoryContents path' return $ map decodeString lst diff --git a/Test.hs b/Test.hs index ebb4cc2..7434266 100644 --- a/Test.hs +++ b/Test.hs @@ -11,11 +11,8 @@ import Network.YAML import TestTypes import Methods -st :: State -st = "test" - -- Declare dispatchingRules for given functions -$(declareRulesWithArg 'st ['double, 'mySum, 'counter, 'ls]) +$(declareRules ['double, 'mySum, 'counter, 'ls]) main = do putStrLn "Listening..." diff --git a/TestCall.hs b/TestCall.hs index fbb366f..efbcbb9 100644 --- a/TestCall.hs +++ b/TestCall.hs @@ -13,17 +13,14 @@ import Network.YAML import TestTypes import qualified Methods -st :: State -st = "test" - -- declare `double', `mySum' and `ls' as RPC methods -$(remote' 'Methods.double) -$(remote' 'Methods.mySum) -$(remote' 'Methods.ls) +$(remote 'Methods.double) +$(remote 'Methods.mySum) +$(remote 'Methods.ls) -- For example, `ls' is defined in Methods.hs as -- ls :: String -> IO [String] -- Now `ls' is defined here as --- ls :: (ByteString,Int) -> String -> IO [String] +-- ls :: (Connection c) => c -> String -> IO [String] rules host = [("test", (host', 5000), 1), diff --git a/TestTypes.hs b/TestTypes.hs index b0737b4..2f2c53d 100644 --- a/TestTypes.hs +++ b/TestTypes.hs @@ -9,8 +9,6 @@ import Network.YAML.Derive data Point = Point { x :: Double, y :: Double } deriving (Show) -type State = String - -- instance Default Point ... $(deriveDefault ''Point) -- 1.7.2.3