never executed always true always false
    1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
    2 
    3 module Conjure.Language.Expression.Op.Active 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 OpActive x = OpActive x Name
   15     deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
   16 
   17 instance Serialize x => Serialize (OpActive x)
   18 instance Hashable  x => Hashable  (OpActive x)
   19 instance ToJSON    x => ToJSON    (OpActive x) where toJSON = genericToJSON jsonOptions
   20 instance FromJSON  x => FromJSON  (OpActive x) where parseJSON = genericParseJSON jsonOptions
   21 
   22 instance (TypeOf x, Pretty x) => TypeOf (OpActive x) where
   23     typeOf p@(OpActive v n) = do
   24         ty <- typeOf v
   25         case ty of
   26             TypeVariant ts ->
   27                 if elem n (map fst ts)
   28                     then return TypeBool
   29                     else raiseTypeError $ vcat [ pretty p
   30                                                , "The field name isn't a part of the variant type."
   31                                                , pretty ty
   32                                                ]
   33             _ -> raiseTypeError $ vcat [ pretty p
   34                                        , "First argument has to be a variant type."
   35                                        , pretty ty
   36                                        ]
   37 
   38 instance SimplifyOp OpActive x where
   39     simplifyOp _ = na "simplifyOp{OpActive}"
   40 
   41 instance Pretty x => Pretty (OpActive x) where
   42     prettyPrec _ (OpActive a b) = "active" <> prettyList prParens "," [pretty a, pretty b]
   43 
   44 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpActive x) where
   45     varSymBreakingDescription (OpActive a b) = JSON.Object $ KM.fromList
   46         [ ("type", JSON.String "OpActive")
   47         , ("children", JSON.Array $ V.fromList
   48             [ varSymBreakingDescription a
   49             , toJSON b
   50             ])
   51         ]