refactor a bit

Ilya Portnov [2010-04-21 15:40:14]
refactor a bit
Filename
Test.hs
YAMLInstances.hs
diff --git a/Test.hs b/Test.hs
index ea45905..09bc533 100644
--- a/Test.hs
+++ b/Test.hs
@@ -7,12 +7,10 @@ import Dispatcher
 import YAML
 import YAMLInstances

-double :: YamlObject -> IO YamlObject
-double obj = do
-  let (Point x y) = cs obj
-  return $ cs $ Point (x*2) (y*2)
+double :: Point -> IO Point
+double (Point x y) = return $ Point (x*2) (y*2)

-rules = mkRules [("double", double)]
+rules = mkRules [("double", yamlMethod double)]

 main = do
   putStrLn "Listening..."
diff --git a/YAMLInstances.hs b/YAMLInstances.hs
index df6da1b..aa1886a 100644
--- a/YAMLInstances.hs
+++ b/YAMLInstances.hs
@@ -60,3 +60,9 @@ instance ConvertSuccess YamlObject Call where

 instance IsYamlObject Call where

+yamlMethod :: (IsYamlObject a, IsYamlObject b) => (a -> IO b) -> YamlObject -> IO YamlObject
+yamlMethod fn = \obj -> do
+  let x = cs obj
+  y <- fn x
+  return $ cs y
+
ViewGit