--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
--- Portability : non-portable
+-- Portability : non-portable (uses Data.Generics.Basics)
--
-- \"Scrap your boilerplate\" --- Generic programming in Haskell
-- See <http://www.cs.vu.nl/boilerplate/>. The present module
import GHC.Stable -- So we can give Data instance for StablePtr
import GHC.ST -- So we can give Data instance for ST
import GHC.Conc -- So we can give Data instance for MVar & Co.
+import GHC.Arr -- So we can give Data instance for Array
#include "Typeable.h"
2 -> k (k (z (:)))
_ -> error "gunfold"
dataTypeOf _ = listDataType
- dataCast1 = gcast1
+ dataCast1 f = gcast1 f
--
-- The gmaps are given as an illustration.
2 -> k (z Just)
_ -> error "gunfold"
dataTypeOf _ = maybeDataType
- dataCast1 = gcast1
+ dataCast1 f = gcast1 f
------------------------------------------------------------------------------
2 -> k (z Right)
_ -> error "gunfold"
dataTypeOf _ = eitherDataType
- dataCast2 = gcast2
+ dataCast2 f = gcast2 f
------------------------------------------------------------------------------
toConstr _ = error "toConstr"
gunfold _ _ = error "gunfold"
dataTypeOf _ = mkNorepType "Prelude.(->)"
- dataCast2 = gcast2
+ dataCast2 f = gcast2 f
------------------------------------------------------------------------------
tuple0DataType = mkDataType "Prelude.()" [tuple0Constr]
instance Data () where
- toConstr _ = tuple0Constr
+ toConstr () = tuple0Constr
gunfold k z c | constrIndex c == 1 = z ()
gunfold _ _ _ = error "gunfold"
dataTypeOf _ = tuple0DataType
instance (Data a, Data b) => Data (a,b) where
gfoldl f z (a,b) = z (,) `f` a `f` b
- toConstr _ = tuple2Constr
+ toConstr (a,b) = tuple2Constr
gunfold k z c | constrIndex c == 1 = k (k (z (,)))
gunfold _ _ _ = error "gunfold"
dataTypeOf _ = tuple2DataType
- dataCast2 = gcast2
+ dataCast2 f = gcast2 f
------------------------------------------------------------------------------
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 _ = tuple3Constr
+ toConstr (a,b,c) = tuple3Constr
gunfold k z c | constrIndex c == 1 = k (k (k (z (,,))))
gunfold _ _ _ = error "gunfold"
dataTypeOf _ = tuple3DataType
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 _ = tuple4Constr
+ toConstr (a,b,c,d) = tuple4Constr
gunfold k z c = case constrIndex c of
1 -> k (k (k (k (z (,,,)))))
_ -> error "gunfold"
instance (Data a, Data b, Data c, Data d, Data e)
=> Data (a,b,c,d,e) where
gfoldl f z (a,b,c,d,e) = z (,,,,) `f` a `f` b `f` c `f` d `f` e
- toConstr _ = tuple5Constr
+ toConstr (a,b,c,d,e) = tuple5Constr
gunfold k z c = case constrIndex c of
1 -> k (k (k (k (k (z (,,,,))))))
_ -> error "gunfold"
instance (Data a, Data b, Data c, Data d, Data e, Data f)
=> Data (a,b,c,d,e,f) where
gfoldl f z (a,b,c,d,e,f') = z (,,,,,) `f` a `f` b `f` c `f` d `f` e `f` f'
- toConstr _ = tuple6Constr
+ toConstr (a,b,c,d,e,f) = tuple6Constr
gunfold k z c = case constrIndex c of
1 -> k (k (k (k (k (k (z (,,,,,)))))))
_ -> error "gunfold"
=> Data (a,b,c,d,e,f,g) where
gfoldl f z (a,b,c,d,e,f',g) =
z (,,,,,,) `f` a `f` b `f` c `f` d `f` e `f` f' `f` g
- toConstr _ = tuple7Constr
+ toConstr (a,b,c,d,e,f,g) = tuple7Constr
gunfold k z c = case constrIndex c of
1 -> k (k (k (k (k (k (k (z (,,,,,,))))))))
_ -> error "gunfold"
------------------------------------------------------------------------------
+-- The Data instance for Array preserves data abstraction at the cost of inefficiency.
+-- We omit reflection services for the sake of data abstraction.
+instance (Typeable a, Data b, Ix a) => Data (Array a b)
+ where
+ gfoldl f z a = z (listArray (bounds a)) `f` (elems a)
+ toConstr _ = error "toConstr"
+ gunfold _ _ = error "gunfold"
+ dataTypeOf _ = mkNorepType "Data.Array.Array"
+