{-# OPTIONS -fglasgow-exts #-}
module GZip (tests) where
{-
This test illustrates zipping for the company datatypes which we use a
lot. We process two companies that happen to agree on the overall
shape but differ in the salaries in a few positions. So whenever we
encounter salaries we take the maximum of the two.
-}
import Test.HUnit
import Data.Generics
import CompanyDatatypes
-- The main function which prints the result of zippingtests = gzip (\xy -> mkTTmaxSxy) genCom1genCom2~=?output-- NB: the argument has to be eta-expanded to match-- the type of gzip's argument type, which is-- GenericQ (GenericM Maybe)
where
-- Variations on the show case company "genCom"genCom1 = everywhere (mkT (double"Joost")) genComgenCom2 = everywhere (mkT (double"Marlow")) genComdoublex (Ep@(Py _) (Ss)) | x==y = Ep (S (2*s))
double _ e = e-- Sum up two salariesmaxS (Sx) (Sy) = S (maxxy)
-- Make a two-arguments, generic function transformermkTT :: (Typeable a, Typeable b, Typeable c)
=> (a -> a -> a) -> b -> c -> MaybecmkTT (f::a -> a -> a) xy =
case (castx,casty) of
(Just (x'::a),Just (y'::a)) -> cast (fx'y')
_ -> Nothingoutput = Just (C [D"Research" (E (P"Laemmel""Amsterdam") (S8000.0))
[PU (E (P"Joost""Amsterdam") (S2000.0))
,PU (E (P"Marlow""Cambridge") (S4000.0))]
,D"Strategy" (E (P"Blair""London") (S100000.0)) []])