Commit a46db114 authored by simonpj@microsoft.com's avatar simonpj@microsoft.com

Add lengthBag to Bag (using in forthcoming patch)

parent 65277a1c
......@@ -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,
......@@ -41,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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment