never executed always true always false
1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
2
3 module Conjure.Language.Expression.Op.Iff 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 OpIff x = OpIff x x
15 deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
16
17 instance Serialize x => Serialize (OpIff x)
18 instance Hashable x => Hashable (OpIff x)
19 instance ToJSON x => ToJSON (OpIff x) where toJSON = genericToJSON jsonOptions
20 instance FromJSON x => FromJSON (OpIff x) where parseJSON = genericParseJSON jsonOptions
21
22 instance BinaryOperator (OpIff x) where
23 opLexeme _ = L_Iff
24
25 instance (TypeOf x, Pretty x) => TypeOf (OpIff x) where
26 typeOf p@(OpIff a b) = boolToBoolToBool p a b
27
28 instance SimplifyOp OpIff x where
29 simplifyOp (OpIff a b)
30 | fromBool True == a = return b
31 | fromBool True == b = return a
32 simplifyOp _ = na "simplifyOp{OpIff}"
33
34 instance Pretty x => Pretty (OpIff x) where
35 prettyPrec prec op@(OpIff a b) = prettyPrecBinOp prec [op] a b
36
37 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpIff x) where
38 varSymBreakingDescription (OpIff a b) = JSON.Object $ KM.fromList
39 [ ("type", JSON.String "OpIff")
40 , ("children", JSON.Array $ V.fromList
41 [ varSymBreakingDescription a
42 , varSymBreakingDescription b
43 ])
44 , ("symmetricChildren", JSON.Bool True)
45 ]