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