X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FOrdList.lhs;h=328a5c142220d9e651dcec56987ccfaa05e77938;hb=fa6c4bf01427a4191a595afecf90d96b27bad306;hp=7f22b38e495a0af306f935f7b9aa8fa8a6696cfe;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/compiler/utils/OrdList.lhs b/compiler/utils/OrdList.lhs index 7f22b38..328a5c1 100644 --- a/compiler/utils/OrdList.lhs +++ b/compiler/utils/OrdList.lhs @@ -1,4 +1,5 @@ % +% (c) The University of Glasgow 2006 % (c) The AQUA Project, Glasgow University, 1993-1998 % @@ -19,8 +20,9 @@ infixl 5 `snocOL` infixr 5 `consOL` data OrdList a - = Many [a] - | Two (OrdList a) (OrdList a) + = Many [a] -- Invariant: non-empty + | Two (OrdList a) -- Invariant: non-empty + (OrdList a) -- Invariant: non-empty | One a | None @@ -35,14 +37,14 @@ concatOL :: [OrdList a] -> OrdList a nilOL = None unitOL as = One as -snocOL as b = Two as (One b) -consOL a bs = Two (One a) bs -concatOL aas = foldr Two None aas +snocOL None b = One b +snocOL as b = Two as (One b) +consOL a None = One a +consOL a bs = Two (One a) bs +concatOL aas = foldr appOL None aas -isNilOL None = True -isNilOL (One _) = False -isNilOL (Two as bs) = isNilOL as && isNilOL bs -isNilOL (Many xs) = null xs +isNilOL None = True +isNilOL _ = False appOL None bs = bs appOL as None = as @@ -76,8 +78,9 @@ fromOL ol flat None rest = rest flat (One x) rest = x:rest flat (Two a b) rest = flat a (flat b rest) - flat (Many xs) rest = xs ++ rest + flat (Many xs) rest = xs ++ rest toOL :: [a] -> OrdList a +toOL [] = None toOL xs = Many xs \end{code}