[project @ 2003-11-23 22:19:35 by ralf]
authorralf <unknown>
Sun, 23 Nov 2003 22:19:35 +0000 (22:19 +0000)
committerralf <unknown>
Sun, 23 Nov 2003 22:19:35 +0000 (22:19 +0000)
Added the missing Data instance for Either.

Data/Generics/Basics.hs

index 3732e56..16b6a32 100644 (file)
@@ -572,6 +572,26 @@ instance (Data a, Data b) => Data (a,b) where
                    1 -> (undefined,undefined)
   dataTypeOf _ = productDataType
 
+--
+-- Yet another polymorphic datatype constructor.
+-- No surprises.
+--
+
+
+leftConstr     = mkConstr 1 "Left"  Prefix
+rightConstr    = mkConstr 2 "Right" Prefix
+eitherDataType = mkDataType [leftConstr,rightConstr]
+
+instance (Data a, Data b) => Data (Either a b) where
+  gfoldl f z (Left a)   = z Left  `f` a
+  gfoldl f z (Right a)  = z Right `f` a
+  toConstr (Left _)  = leftConstr
+  toConstr (Right _) = rightConstr
+  fromConstr c = case conIndex c of
+                   1 -> Left undefined
+                   2 -> Right undefined
+  dataTypeOf _ = eitherDataType
+
 
 {-