Skip to content

Commit

Permalink
cardinality on lists and matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgurakgun committed Jun 6, 2016
1 parent 9308fd5 commit b282d38
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Conjure/Language/Expression/Op/TwoBars.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Conjure.Language.Expression.Op.TwoBars where
import Conjure.Prelude
import Conjure.Language.Expression.Op.Internal.Common
import Conjure.Language.DomainSizeOf
import Conjure.Language.NameGen ( runNameGen)

import qualified Data.Aeson as JSON -- aeson
import qualified Data.HashMap.Strict as M -- unordered-containers
Expand All @@ -24,6 +25,7 @@ instance (TypeOf x, Pretty x) => TypeOf (OpTwoBars x) where
ty <- typeOf a
case ty of
TypeInt{} -> return ()
TypeList{} -> return ()
TypeSet{} -> return ()
TypeMSet{} -> return ()
TypeFunction{} -> return ()
Expand All @@ -40,17 +42,17 @@ instance EvaluateOp OpTwoBars where
ConstantInt y -> return $ ConstantInt $ abs y

-- cardinality of a constant
(viewConstantSet -> Just xs) -> return $ ConstantInt $ genericLength $ nub xs
(viewConstantMSet -> Just xs) -> return $ ConstantInt $ genericLength xs
(viewConstantFunction -> Just xs) -> return $ ConstantInt $ genericLength $ nub xs
(viewConstantSequence -> Just xs) -> return $ ConstantInt $ genericLength xs
(viewConstantRelation -> Just xs) -> return $ ConstantInt $ genericLength $ nub xs
(viewConstantPartition -> Just xs) -> return $ ConstantInt $ genericLength $ nub $ concat xs
(viewConstantMatrix -> Just (_, xs)) -> return $ ConstantInt $ genericLength xs
(viewConstantSet -> Just xs) -> return $ ConstantInt $ genericLength $ nub xs
(viewConstantMSet -> Just xs) -> return $ ConstantInt $ genericLength xs
(viewConstantFunction -> Just xs) -> return $ ConstantInt $ genericLength $ nub xs
(viewConstantSequence -> Just xs) -> return $ ConstantInt $ genericLength xs
(viewConstantRelation -> Just xs) -> return $ ConstantInt $ genericLength $ nub xs
(viewConstantPartition -> Just xs) -> return $ ConstantInt $ genericLength $ nub $ concat xs

-- cardinality of a domain
DomainInConstant (DomainInt rs) -> ConstantInt . genericLength <$> rangesInts rs
DomainInConstant dom -> domainSizeOf dom

DomainInConstant dom -> runNameGen $ domainSizeOf dom
_ -> na $ "evaluateOp OpTwoBars" <+> pretty (show x)

instance SimplifyOp OpTwoBars x where
Expand Down

0 comments on commit b282d38

Please sign in to comment.