Mercurial > 12ws.info2
diff exercises/src/SetPairList.hs @ 26:ce9610f08925
Merge
author | Markus Kaiser <markus.kaiser@in.tum.de> |
---|---|
date | Wed, 09 Jan 2013 19:45:47 +0100 |
parents | 34fea195e238 ea3fba2381bc |
children |
line wrap: on
line diff
--- a/exercises/src/SetPairList.hs Fri Dec 21 01:44:45 2012 +0100 +++ b/exercises/src/SetPairList.hs Wed Jan 09 19:45:47 2013 +0100 @@ -1,35 +1,48 @@ --- ? +module SetPairList(Set, empty, insert, isin, size, union, delete) where -- Abstraction function {- - alpha (S x) = undefined + alpha :: Set a -> {a} + alpha (S []) = {} + alpha (S ((a, b):xs)) = {a..b} union (alpha xs) To show: (10 things) + alpha empty = {} + invar s ==> alpha (insert x s) = {x} union alpha s + invar s ==> alpha (delete x s) = alpha s \ {x} + invar s ==> isin x s = x \in alpha s + invar s ==> size s = |alpha s| + invar s1, invar s2 ==> alpha (union s1 s2) = (alpha s1) union (alpha s2) + + invar empty + invar s ==> invar (insert x s) + invar s ==> invar(delete x s) + invar s1, invar s2 ==> invar (union s1 s2) -} -- Interface -newtype Set a = S (...) +newtype Set a = S (PairList a) invar :: Integral a => Set a -> Bool -invar (S s) = undefined +invar (S s) = invarPL s empty :: Set a -empty = undefined +empty = S emptyPL insert :: Integral a => a -> Set a -> Set a -insert n (S s) = undefined +insert n (S s) = S (insertPL n s) isin :: Integral a => a -> Set a -> Bool -isin n (S s) = undefined +isin n (S s) = isinPL n s size :: Integral a => Set a -> Integer -size (S s) = undefined +size (S s) = sizePL s union :: Integral a => Set a -> Set a -> Set a -union (S s1) (S s2) = undefined +union (S s1) (S s2) = S (unionPL s1 s2) delete :: Integral a => a -> Set a -> Set a -delete n (S s) = undefined +delete n (S s) = S (deletePL n s) -- Implementation type PairList a = [(a, a)]