diff options
author | klebinger.andreas@gmx.at <klebinger.andreas@gmx.at> | 2019-01-24 23:02:51 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2019-01-31 12:46:51 -0500 |
commit | ff2d6018348c6d316b87c596a4010b316501b91c (patch) | |
tree | e29015ad6e473f09a285a68635e9f4b9a44f0be2 /compiler/utils/OrdList.hs | |
parent | 5b970d8e06c1433066a8c587116f0b22c0f30e22 (diff) | |
download | haskell-ff2d6018348c6d316b87c596a4010b316501b91c.tar.gz |
Replace BlockSequence with OrdList in BlockLayout.hs
OrdList does the same thing and more so there is no reason
to have both.
Diffstat (limited to 'compiler/utils/OrdList.hs')
-rw-r--r-- | compiler/utils/OrdList.hs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/compiler/utils/OrdList.hs b/compiler/utils/OrdList.hs index 064712bbad..2d7a43f228 100644 --- a/compiler/utils/OrdList.hs +++ b/compiler/utils/OrdList.hs @@ -12,7 +12,8 @@ can be appended in linear time. module OrdList ( OrdList, nilOL, isNilOL, unitOL, appOL, consOL, snocOL, concatOL, lastOL, - mapOL, fromOL, toOL, foldrOL, foldlOL, reverseOL + headOL, + mapOL, fromOL, toOL, foldrOL, foldlOL, reverseOL, fromOLReverse ) where import GhcPrelude @@ -62,14 +63,23 @@ snocOL :: OrdList a -> a -> OrdList a consOL :: a -> OrdList a -> OrdList a appOL :: OrdList a -> OrdList a -> OrdList a concatOL :: [OrdList a] -> OrdList a +headOL :: OrdList a -> a lastOL :: OrdList a -> a + nilOL = None unitOL as = One as snocOL as b = Snoc as b consOL a bs = Cons a bs concatOL aas = foldr appOL None aas +headOL None = panic "headOL" +headOL (One a) = a +headOL (Many as) = head as +headOL (Cons a _) = a +headOL (Snoc as _) = headOL as +headOL (Two as _) = headOL as + lastOL None = panic "lastOL" lastOL (One a) = a lastOL (Many as) = last as @@ -95,6 +105,17 @@ fromOL a = go a [] go (Two a b) acc = go a (go b acc) go (Many xs) acc = xs ++ acc +fromOLReverse :: OrdList a -> [a] +fromOLReverse a = go a [] + -- acc is already in reverse order + where go :: OrdList a -> [a] -> [a] + go None acc = acc + go (One a) acc = a : acc + go (Cons a b) acc = go b (a : acc) + go (Snoc a b) acc = b : go a acc + go (Two a b) acc = go b (go a acc) + go (Many xs) acc = reverse xs ++ acc + mapOL :: (a -> b) -> OrdList a -> OrdList b mapOL _ None = None mapOL f (One x) = One (f x) |