X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FBag.lhs;h=ebc44ac1479975276eb13f755ed0b1b4f974bb3e;hb=479b0241032c8b02999e0852f63d57fe3584edf9;hp=e53d23dc0cfd8083c4e2de73279592728e9e41aa;hpb=e4cdbb7b821b1ee6dfb0d7a5ef7275edab6a0520;p=ghc-hetmet.git diff --git a/compiler/utils/Bag.lhs b/compiler/utils/Bag.lhs index e53d23d..ebc44ac 100644 --- a/compiler/utils/Bag.lhs +++ b/compiler/utils/Bag.lhs @@ -11,7 +11,7 @@ module Bag ( emptyBag, unitBag, unionBags, unionManyBags, mapBag, - elemBag, + elemBag, lengthBag, filterBag, partitionBag, concatBag, foldBag, foldrBag, foldlBag, isEmptyBag, isSingletonBag, consBag, snocBag, anyBag, listToBag, bagToList, @@ -22,6 +22,9 @@ import Outputable import Util ( isSingleton ) import Data.List ( partition ) + +infixr 3 `consBag` +infixl 3 `snocBag` \end{code} @@ -38,6 +41,12 @@ emptyBag = EmptyBag unitBag :: a -> Bag a unitBag = UnitBag +lengthBag :: Bag a -> Int +lengthBag EmptyBag = 0 +lengthBag (UnitBag {}) = 1 +lengthBag (TwoBags b1 b2) = lengthBag b1 + lengthBag b2 +lengthBag (ListBag xs) = length xs + elemBag :: Eq a => a -> Bag a -> Bool elemBag _ EmptyBag = False elemBag x (UnitBag y) = x == y @@ -178,5 +187,5 @@ bagToList b = foldrBag (:) [] b \begin{code} instance (Outputable a) => Outputable (Bag a) where - ppr bag = char '<' <> pprWithCommas ppr (bagToList bag) <> char '>' + ppr bag = braces (pprWithCommas ppr (bagToList bag)) \end{code}