never executed always true always false
1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
2
3 module Conjure.Language.Expression.Op.GCC 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 OpGCC x = OpGCC x -- X: variables
15 x -- v[i] values, indexed by T
16 x -- o[i] is the nb of occurrences of v[i] in X, indexed by T
17 deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
18
19 instance Serialize x => Serialize (OpGCC x)
20 instance Hashable x => Hashable (OpGCC x)
21 instance ToJSON x => ToJSON (OpGCC x) where toJSON = genericToJSON jsonOptions
22 instance FromJSON x => FromJSON (OpGCC x) where parseJSON = genericParseJSON jsonOptions
23
24 instance (TypeOf x, Pretty x) => TypeOf (OpGCC x) where
25 typeOf p@(OpGCC vars vals occs) = do
26 tyVars <- typeOf vars
27 tyVals <- typeOf vals
28 tyOccs <- typeOf occs
29 let
30 tyError = raiseTypeError $ vcat [ pretty p
31 , pretty vars <+> "has type" <+> pretty tyVars
32 , pretty vals <+> "has type" <+> pretty tyVals
33 , pretty occs <+> "has type" <+> pretty tyOccs
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
42 return TypeBool
43
44 instance SimplifyOp OpGCC x where
45 simplifyOp _ = na "simplifyOp{OpGCC}"
46
47 instance Pretty x => Pretty (OpGCC x) where
48 prettyPrec _ (OpGCC a b c) = "gcc" <> prettyList prParens "," [a, b, c]
49
50 instance (VarSymBreakingDescription x, ExpressionLike x) => VarSymBreakingDescription (OpGCC x) where
51 varSymBreakingDescription (OpGCC a b c) = JSON.Object $ KM.fromList
52 [ ("type", JSON.String "OpGCC")
53 , ("children", JSON.Array $ V.fromList [ varSymBreakingDescription a
54 , varSymBreakingDescription b
55 , varSymBreakingDescription c
56 ])
57 , ("symmetricChildren", JSON.Bool True)
58 ]