never executed always true always false
    1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
    2 {-# LANGUAGE UndecidableInstances #-}
    3 
    4 module Conjure.Language.Expression.Op.Xor where
    5 
    6 import Conjure.Prelude
    7 import Conjure.Language.Expression.Op.Internal.Common
    8 
    9 import qualified Data.Aeson as JSON             -- aeson
   10 import qualified Data.Aeson.KeyMap as KM
   11 
   12 import qualified Data.Vector as V               -- vector
   13 
   14 
   15 -- true if an odd number of its arguments are true, and false otherwise
   16 data OpXor x = OpXor x
   17     deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
   18 
   19 instance Serialize x => Serialize (OpXor x)
   20 instance Hashable  x => Hashable  (OpXor x)
   21 instance ToJSON    x => ToJSON    (OpXor x) where toJSON = genericToJSON jsonOptions
   22 instance FromJSON  x => FromJSON  (OpXor x) where parseJSON = genericParseJSON jsonOptions
   23 
   24 instance (TypeOf x, Pretty x, ExpressionLike x) => TypeOf (OpXor x) where
   25     typeOf p@(OpXor x) = do
   26         ty <- typeOf x
   27         case ty of
   28             TypeList TypeAny -> return TypeBool
   29             TypeList TypeBool -> return TypeBool
   30             TypeMatrix _ TypeAny -> return TypeBool
   31             TypeMatrix _ TypeBool -> return TypeBool
   32             TypeSet TypeBool -> return TypeBool
   33             TypeMSet TypeBool -> return TypeBool
   34             _ -> raiseTypeError $ vcat [ pretty p
   35                                        , "The argument has type:" <+> pretty ty
   36                                        ]
   37 
   38 instance (OpXor x :< x) => SimplifyOp OpXor x where
   39     simplifyOp _ = na "simplifyOp{OpXor}"
   40 
   41 instance (Pretty x, ExpressionLike x) => Pretty (OpXor x) where
   42     prettyPrec _ (OpXor x) = "xor" <> prParens (pretty x)
   43 
   44 instance (VarSymBreakingDescription x, ExpressionLike x) => VarSymBreakingDescription (OpXor x) where
   45     varSymBreakingDescription (OpXor x) | Just xs <- listOut x = JSON.Object $ KM.fromList
   46         [ ("type", JSON.String "OpXor")
   47         , ("children", JSON.Array $ V.fromList $ map varSymBreakingDescription xs)
   48         , ("symmetricChildren", JSON.Bool True)
   49         ]
   50     varSymBreakingDescription (OpXor x) = JSON.Object $ KM.fromList
   51         [ ("type", JSON.String "OpXor")
   52         , ("children", varSymBreakingDescription x)
   53         ]