X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FOrdList.lhs;h=7194bc3c6c56eb6c1a54d112288d8aed5e7b1bcd;hb=7fc749a43b4b6b85d234fa95d4928648259584f4;hp=7e797e096b26639e584580f6ff6094b027acbd6a;hpb=046ee54f048ddd721dcee41916d6a6f68db3b15b;p=ghc-hetmet.git diff --git a/compiler/utils/OrdList.lhs b/compiler/utils/OrdList.lhs index 7e797e0..7194bc3 100644 --- a/compiler/utils/OrdList.lhs +++ b/compiler/utils/OrdList.lhs @@ -9,6 +9,13 @@ Provide trees (of instructions), so that lists of instructions can be appended in linear time. \begin{code} +{-# OPTIONS -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + module OrdList ( OrdList, nilOL, isNilOL, unitOL, appOL, consOL, snocOL, concatOL, @@ -20,8 +27,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 @@ -36,14 +44,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 @@ -77,8 +85,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}