never executed always true always false
    1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
    2 
    3 module Conjure.Language.Expression.Op.In 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 OpIn x = OpIn x x
   15     deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
   16 
   17 instance Serialize x => Serialize (OpIn x)
   18 instance Hashable  x => Hashable  (OpIn x)
   19 instance ToJSON    x => ToJSON    (OpIn x) where toJSON = genericToJSON jsonOptions
   20 instance FromJSON  x => FromJSON  (OpIn x) where parseJSON = genericParseJSON jsonOptions
   21 instance BinaryOperator (OpIn x) where
   22     opLexeme _ = L_in
   23 
   24 instance (TypeOf x, Pretty x) => TypeOf (OpIn x) where
   25     typeOf p@(OpIn a b) = do
   26         tyA      <- typeOf a
   27         tyB      <- typeOf b
   28         case innerTypeOf tyB of
   29             Nothing -> raiseTypeError p
   30             Just tyBInner ->
   31                 if tyA `typeUnify` tyBInner
   32                     then return TypeBool
   33                     else raiseTypeError $ vcat [ pretty p
   34                                                , pretty a <+> "has type" <+> pretty tyA
   35                                                , pretty b <+> "has type" <+> pretty tyB
   36                                                ]
   37 
   38 instance SimplifyOp OpIn x where
   39     simplifyOp _ = na "simplifyOp{OpIn}"
   40 
   41 instance Pretty x => Pretty (OpIn x) where
   42     prettyPrec prec op@(OpIn a b) = prettyPrecBinOp prec [op] a b
   43 
   44 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpIn x) where
   45     varSymBreakingDescription (OpIn a b) = JSON.Object $ KM.fromList
   46         [ ("type", JSON.String "OpIn")
   47         , ("children", JSON.Array $ V.fromList
   48             [ varSymBreakingDescription a
   49             , varSymBreakingDescription b
   50             ])
   51         ]