[project @ 2004-01-14 14:58:57 by ralf]
authorralf <unknown>
Wed, 14 Jan 2004 14:58:57 +0000 (14:58 +0000)
committerralf <unknown>
Wed, 14 Jan 2004 14:58:57 +0000 (14:58 +0000)
Added gdepth to determine depth of a term.

Data/Generics/Reify.hs

index a5f5244..9e70fbb 100644 (file)
@@ -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)