From: ralf Date: Sun, 23 Nov 2003 22:19:35 +0000 (+0000) Subject: [project @ 2003-11-23 22:19:35 by ralf] X-Git-Tag: nhc98-1-18-release~438 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=aa892b1ecac3f5b19b7b1a02367f347f545d9914;p=ghc-base.git [project @ 2003-11-23 22:19:35 by ralf] Added the missing Data instance for Either. --- diff --git a/Data/Generics/Basics.hs b/Data/Generics/Basics.hs index 3732e56..16b6a32 100644 --- a/Data/Generics/Basics.hs +++ b/Data/Generics/Basics.hs @@ -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 + {-