module Text.Tabl.Decoration
( Decoration(..)
, presence
) where
data Decoration
= DecorNone
| DecorAll
| DecorInner
| DecorOuter
| DecorOnly [Int]
| DecorExcept [Int]
| DecorUnion [Decoration]
| DecorIsect [Decoration]
deriving (Show)
presence :: Int
-> Decoration
-> [Bool]
presence n DecorNone = replicate n False
presence n DecorAll = replicate n True
presence n DecorInner = [False] ++ replicate (n2) True ++ [False]
presence n DecorOuter = [True] ++ replicate (n2) False ++ [True]
presence n (DecorOnly is) = map (`elem` is) [0..(n1)]
presence n (DecorExcept is) = map not (presence n (DecorOnly is))
presence n (DecorUnion ds) = combine (||) False n ds
presence n (DecorIsect ds) = combine (&&) True n ds
combine :: (Bool -> Bool -> Bool)
-> Bool
-> Int
-> [Decoration]
-> [Bool]
combine fn def n ds = foldr step first presences
where
first = replicate n def
step = zipWith fn
presences = map (presence n) ds