From 4c8456b0aa4f8dd54dd76103685c5bea71feb5d5 Mon Sep 17 00:00:00 2001 From: ralf Date: Sat, 6 Dec 2003 17:48:49 +0000 Subject: [PATCH] [project @ 2003-12-06 17:48:49 by ralf] Added Data instances for triples and quadruples. --- Data/Generics/Basics.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Data/Generics/Basics.hs b/Data/Generics/Basics.hs index 16b6a32..7e7cf7c 100644 --- a/Data/Generics/Basics.hs +++ b/Data/Generics/Basics.hs @@ -557,6 +557,7 @@ instance Data a => Data (Maybe a) where 2 -> Just undefined dataTypeOf _ = maybeDataType + -- -- Yet another polymorphic datatype constructor. -- No surprises. @@ -572,12 +573,38 @@ instance (Data a, Data b) => Data (a,b) where 1 -> (undefined,undefined) dataTypeOf _ = productDataType + -- -- Yet another polymorphic datatype constructor. -- No surprises. -- + +tripleConstr = mkConstr 1 "(,,)" Infix +tripleDataType = mkDataType [tripleConstr] + +instance (Data a, Data b, Data c) => Data (a,b,c) where + gfoldl f z (a,b,c) = z (,,) `f` a `f` b `f` c + toConstr _ = tripleConstr + fromConstr c = case conIndex c of + 1 -> (undefined,undefined,undefined) + dataTypeOf _ = tripleDataType + +quadrupleConstr = mkConstr 1 "(,,,)" Infix +quadrupleDataType = mkDataType [quadrupleConstr] + +instance (Data a, Data b, Data c, Data d) => Data (a,b,c,d) where + gfoldl f z (a,b,c,d) = z (,,,) `f` a `f` b `f` c `f` d + toConstr _ = quadrupleConstr + fromConstr c = case conIndex c of + 1 -> (undefined,undefined,undefined,undefined) + dataTypeOf _ = quadrupleDataType +-- +-- Yet another polymorphic datatype constructor. +-- No surprises. +-- + leftConstr = mkConstr 1 "Left" Prefix rightConstr = mkConstr 2 "Right" Prefix eitherDataType = mkDataType [leftConstr,rightConstr] -- 1.7.10.4