never executed always true always false
    1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
    2 
    3 module Conjure.Language.Expression.Op.AtMost where
    4 
    5 import Conjure.Prelude
    6 import Conjure.Language.Expression.Op.Internal.Common
    7 
    8 import qualified Data.Aeson as JSON             -- aeson
    9 import qualified Data.Aeson.KeyMap as KM
   10 
   11 import qualified Data.Vector as V               -- vector
   12 
   13 
   14 data OpAtMost x = OpAtMost x -- X: variables
   15                            x -- o[i] is an upper bound for the nb of occurrences of v[i] in X, indexed by T
   16                            x -- v[i] values, indexed by T
   17     deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
   18 
   19 instance Serialize x => Serialize (OpAtMost x)
   20 instance Hashable  x => Hashable  (OpAtMost x)
   21 instance ToJSON    x => ToJSON    (OpAtMost x) where toJSON = genericToJSON jsonOptions
   22 instance FromJSON  x => FromJSON  (OpAtMost x) where parseJSON = genericParseJSON jsonOptions
   23 
   24 instance (TypeOf x, Pretty x) => TypeOf (OpAtMost x) where
   25     typeOf p@(OpAtMost vars occs vals) = do
   26         tyVars <- typeOf vars
   27         tyOccs <- typeOf occs
   28         tyVals <- typeOf vals
   29         let
   30             tyError = raiseTypeError $ vcat [ pretty p
   31                                             , pretty vars <+> "has type" <+> pretty tyVars
   32                                             , pretty occs <+> "has type" <+> pretty tyOccs
   33                                             , pretty vals <+> "has type" <+> pretty tyVals
   34                                             ]
   35             listLike (TypeList TypeInt{}) = return ()
   36             listLike (TypeMatrix _ TypeInt{}) = return ()
   37             listLike _ = tyError
   38         listLike tyVars
   39         listLike tyVals
   40         listLike tyOccs
   41         -- TODO: check the indices and the category of vals&occs
   42         return TypeBool
   43 
   44 instance SimplifyOp OpAtMost x where
   45     simplifyOp _ = na "simplifyOp{OpAtMost}"
   46 
   47 instance Pretty x => Pretty (OpAtMost x) where
   48     prettyPrec _ (OpAtMost a b c) = "atmost" <> prettyList prParens "," [a, b, c]
   49 
   50 instance (VarSymBreakingDescription x, ExpressionLike x) => VarSymBreakingDescription (OpAtMost x) where
   51     varSymBreakingDescription (OpAtMost a b c) = JSON.Object $ KM.fromList
   52         [ ("type", JSON.String "OpAtMost")
   53         , ("children", JSON.Array $ V.fromList [ varSymBreakingDescription a
   54                                                , varSymBreakingDescription b
   55                                                , varSymBreakingDescription c
   56                                                ])
   57         , ("symmetricChildren", JSON.Bool True)
   58         ]