From c4f147f5db4a0cf4c3d955ba8c2792f8fca5cbf9 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Mon, 7 Apr 2008 22:31:18 +0000 Subject: [PATCH] Rewrite findMeta in terms of listify. It'll now recurse into the data item you give it, which means it works on types like Actual where the Meta isn't an immediate child. --- data/Metadata.hs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/data/Metadata.hs b/data/Metadata.hs index 57efb36..597921e 100644 --- a/data/Metadata.hs +++ b/data/Metadata.hs @@ -70,11 +70,9 @@ unpackMeta s getInt s = case readDec s of [(v, "")] -> v -- | Find the first Meta value in some part of the AST. -findMeta :: (Data t, Typeable t) => t -> Meta -findMeta e = case cast e of - Just m -> m - Nothing -> if null (concat metaList) then emptyMeta else head (concat metaList) - where - metaList = gmapQ (mkQ [] findMeta') e - findMeta' :: Meta -> [Meta] - findMeta' m = [m] +-- Return 'emptyMeta' if it couldn't find one. +findMeta :: Data t => t -> Meta +findMeta e + = case listify (const True :: Meta -> Bool) e of + (m:_) -> m + [] -> emptyMeta