module Multilinear.Index (
Index(..),
TIndex(..)
) where
class Index i where
indexName :: i -> String
isCovariant :: i -> Bool
isContravariant :: i -> Bool
isIndifferent :: i -> Bool
equivI :: i -> i -> Bool
infixl 2 !=!
(!=!) :: i -> i -> Bool
i1 !=! i2 = equivI i1 i2
toTIndex :: i -> TIndex
data TIndex =
Covariant {
indexSize :: Maybe Int,
tIndexName :: String
} |
Contravariant {
indexSize :: Maybe Int,
tIndexName :: String
} |
Indifferent {
indexSize :: Maybe Int,
tIndexName :: String
}
deriving Eq
instance Show TIndex where
show (Covariant c n) = "[" ++ n ++ ":" ++ show c ++ "]"
show (Contravariant c n) = "<" ++ n ++ ":" ++ show c ++ ">"
show (Indifferent c n) = "(" ++ n ++ ":" ++ show c ++ ")"
instance Index TIndex where
indexName = tIndexName
isCovariant (Covariant _ _) = True
isCovariant _ = False
isContravariant (Contravariant _ _) = True
isContravariant _ = False
isIndifferent (Indifferent _ _) = True
isIndifferent _ = False
equivI (Covariant count1 _) (Covariant count2 _)
| count1 == count2 = True
| otherwise = False
equivI (Contravariant count1 _) (Contravariant count2 _)
| count1 == count2 = True
| otherwise = False
equivI (Indifferent count1 _) (Indifferent count2 _)
| count1 == count2 = True
| otherwise = False
equivI _ _ = False
toTIndex = id
instance Ord TIndex where
ind1 <= ind2 = indexSize ind1 <= indexSize ind2