module Multilinear.Index.Finite (
Index(..),
) where
import Control.DeepSeq
import GHC.Generics
import qualified Multilinear.Index as TIndex
data Index =
Covariant {
indexSize :: Int,
indexName' :: String
} |
Contravariant {
indexSize :: Int,
indexName' :: String
} |
Indifferent {
indexSize :: Int,
indexName' :: String
}
deriving (Eq, Generic)
instance Show Index where
show (Covariant c n) = "[" ++ n ++ ":" ++ show c ++ "]"
show (Contravariant c n) = "<" ++ n ++ ":" ++ show c ++ ">"
show (Indifferent c n) = "(" ++ n ++ ":" ++ show c ++ ")"
instance TIndex.Index Index where
indexName = indexName'
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 (Covariant size name) = TIndex.Covariant (Just size) name
toTIndex (Contravariant size name) = TIndex.Contravariant (Just size) name
toTIndex (Indifferent size name) = TIndex.Indifferent (Just size) name
instance Ord Index where
ind1 <= ind2 = indexSize ind1 <= indexSize ind2
instance NFData Index