From: ralf Date: Wed, 14 Jan 2004 14:58:57 +0000 (+0000) Subject: [project @ 2004-01-14 14:58:57 by ralf] X-Git-Tag: nhc98-1-18-release~406 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=2de78af58401cb3d9dcdec50326d794f4c65a374;p=ghc-base.git [project @ 2004-01-14 14:58:57 by ralf] Added gdepth to determine depth of a term. --- diff --git a/Data/Generics/Reify.hs b/Data/Generics/Reify.hs index a5f5244..9e70fbb 100644 --- a/Data/Generics/Reify.hs +++ b/Data/Generics/Reify.hs @@ -34,6 +34,7 @@ module Data.Generics.Reify ( -- * Generic operations to reify terms glength, + gdepth, gcount, gnodecount, gtypecount, @@ -156,6 +157,11 @@ glength :: GenericQ Int glength = length . gmapQ (const ()) +-- | Determine depth of the given term +gdepth :: GenericQ Int +gdepth = (+) 1 . foldr max 0 . gmapQ gdepth + + -- | Determine the number of all suitable nodes in a given term gcount :: GenericQ Bool -> GenericQ Int gcount p = everything (+) (\x -> if p x then 1 else 0)