2 % (c) The AQUA Project, Glasgow University, 1993-1998
5 This is useful, general stuff for the Native Code Generator.
7 Provide trees (of instructions), so that lists of instructions
8 can be appended in linear time.
13 nilOL, isNilOL, unitOL, appOL, consOL, snocOL, concatOL,
22 = Many (OrdList a) (OrdList a)
27 isNilOL :: OrdList a -> Bool
29 unitOL :: a -> OrdList a
30 snocOL :: OrdList a -> a -> OrdList a
31 consOL :: a -> OrdList a -> OrdList a
32 appOL :: OrdList a -> OrdList a -> OrdList a
33 concatOL :: [OrdList a] -> OrdList a
37 snocOL as b = Many as (One b)
38 consOL a bs = Many (One a) bs
39 concatOL aas = foldr Many None aas
42 isNilOL (One _) = False
43 isNilOL (Many as bs) = isNilOL as && isNilOL bs
47 appOL as bs = Many as bs
49 fromOL :: OrdList a -> [a]
54 flat (One x) rest = x:rest
55 flat (Many a b) rest = flat a (flat b rest)
57 toOL :: [a] -> OrdList a
59 toOL (x:xs) = Many (One x) (toOL xs)