Support Transforms.optimize

Partially optimize inputs and document rules for further optimizations we can
make.
This commit is contained in:
William Carroll 2020-08-06 00:15:31 +01:00
parent d45685e245
commit e14fff7d4b
2 changed files with 19 additions and 0 deletions

View file

@ -33,6 +33,18 @@ command = vertical
Nothing -> pure $ Shift n
Just _ -> pure $ Shift (-1 * n)
-- | Attempt to remove redundant transformations.
-- | Here are some rules that I'd like to support but may not have time for:
-- | - All even-numbered flips (w/o intermittent shifts) can become zero
-- | - All odd-numbered flips (w/o intermittent shifts) can become 1
-- | - All shifts can be be reduce to the absolute value of shifts
optimize :: [Transform] -> [Transform]
optimize [] = []
optimize [x] = [x]
optimize (VerticalFlip:VerticalFlip:xs) = optimize xs
optimize (HorizontalFlip:HorizontalFlip:xs) = optimize xs
optimize xs = xs
fromString :: String -> Maybe [Transform]
fromString x =
case readP_to_S (manyTill command eof) x of