From 9466a22eb6170626c5edd8d96edb361975454c15 Mon Sep 17 00:00:00 2001 From: Ilya Portnov Date: Sat, 8 May 2010 20:14:03 +0600 Subject: [PATCH] add instance IsYamlObject (Either a b) --- Network/YAML/Instances.hs | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/Network/YAML/Instances.hs b/Network/YAML/Instances.hs index 4ed4d81..2ad71d2 100644 --- a/Network/YAML/Instances.hs +++ b/Network/YAML/Instances.hs @@ -67,6 +67,30 @@ instance (Default a, Default b) => Default (a,b) where instance (Default a, Default b, Default c) => Default (a,b,c) where def = (def, def, def) +_right :: BS.ByteString +_right = "Right" + +_left :: BS.ByteString +_left = "Left" + +instance (IsYamlObject a, IsYamlObject b) => ConvertSuccess (Either a b) YamlObject where + convertSuccess (Right a) = Mapping [(toYamlScalar _right, cs a)] + convertSuccess (Left b) = Mapping [(toYamlScalar _left, cs b)] + +instance (IsYamlObject a, IsYamlObject b) => ConvertSuccess YamlObject (Either a b) where + convertSuccess (Mapping [(name, val)]) = + if fromYamlScalar name == _right + then Right (cs val) + else if fromYamlScalar name == _left + then Left (cs val) + else def + convertSuccess _ = def + +instance (Default a) => Default (Either a b) where + def = Left def + +instance (IsYamlObject a, IsYamlObject b) => IsYamlObject (Either a b) where + instance Default YamlObject where def = Sequence [] -- 1.7.2.3