never executed always true always false
    1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
    2 
    3 module Conjure.Language.Expression.Op.Defined 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 OpDefined x = OpDefined x
   15     deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
   16 
   17 instance Serialize x => Serialize (OpDefined x)
   18 instance Hashable  x => Hashable  (OpDefined x)
   19 instance ToJSON    x => ToJSON    (OpDefined x) where toJSON = genericToJSON jsonOptions
   20 instance FromJSON  x => FromJSON  (OpDefined x) where parseJSON = genericParseJSON jsonOptions
   21 
   22 instance (Pretty x, TypeOf x) => TypeOf (OpDefined x) where
   23     typeOf p@(OpDefined x) = do
   24         ty <- typeOf x
   25         case ty of
   26             TypeFunction a _ -> return (TypeSet a)
   27             TypeSequence _   -> return (TypeSet (TypeInt TagInt))
   28             _                -> raiseTypeError p
   29 
   30 instance SimplifyOp OpDefined x where
   31     simplifyOp _ = na "simplifyOp{OpDefined}"
   32 
   33 instance Pretty x => Pretty (OpDefined x) where
   34     prettyPrec _ (OpDefined a) = "defined" <> prParens (pretty a)
   35 
   36 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpDefined x) where
   37     varSymBreakingDescription (OpDefined a) = JSON.Object $ KM.fromList
   38         [ ("type", JSON.String "OpDefined")
   39         , ("children", JSON.Array $ V.fromList
   40             [ varSymBreakingDescription a
   41             ])
   42         ]