never executed always true always false
1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
2
3 module Conjure.Language.Expression.Op.Minus 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 OpMinus x = OpMinus x x
15 deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
16
17 instance Serialize x => Serialize (OpMinus x)
18 instance Hashable x => Hashable (OpMinus x)
19 instance ToJSON x => ToJSON (OpMinus x) where toJSON = genericToJSON jsonOptions
20 instance FromJSON x => FromJSON (OpMinus x) where parseJSON = genericParseJSON jsonOptions
21
22 instance BinaryOperator (OpMinus x) where
23 opLexeme _ = L_Minus
24
25 instance (TypeOf x, Pretty x) => TypeOf (OpMinus x) where
26 typeOf p@(OpMinus a b) = sameToSameToSame p a b
27 [ TypeSet TypeAny
28 , TypeMSet TypeAny
29 , TypeFunction TypeAny TypeAny
30 , TypeRelation [TypeAny]
31 ]
32 (\ ty -> case (?typeCheckerMode, ty) of
33 (StronglyTyped, TypeInt TagInt) -> True
34 (RelaxedIntegerTags, TypeInt{}) -> True
35 _ -> False
36 )
37
38 instance SimplifyOp OpMinus x where
39 simplifyOp _ = na "simplifyOp{OpMinus}"
40
41 instance Pretty x => Pretty (OpMinus x) where
42 prettyPrec prec op@(OpMinus a b) = prettyPrecBinOp prec [op] a b
43
44 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpMinus x) where
45 varSymBreakingDescription (OpMinus a b) = JSON.Object $ KM.fromList
46 [ ("type", JSON.String "OpMinus")
47 , ("children", JSON.Array $ V.fromList
48 [ varSymBreakingDescription a
49 , varSymBreakingDescription b
50 ])
51 ]