never executed always true always false
    1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
    2 
    3 module Conjure.Language.Expression.Op.Image 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 OpImage x = OpImage x x
   15     deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
   16 
   17 instance Serialize x => Serialize (OpImage x)
   18 instance Hashable  x => Hashable  (OpImage x)
   19 instance ToJSON    x => ToJSON    (OpImage x) where toJSON = genericToJSON jsonOptions
   20 instance FromJSON  x => FromJSON  (OpImage x) where parseJSON = genericParseJSON jsonOptions
   21 
   22 instance (TypeOf x, Pretty x) => TypeOf (OpImage x) where
   23     typeOf p@(OpImage f x) = do
   24         tyF <- typeOf f
   25         (from, to) <- case tyF of
   26             TypeFunction from to -> return (from, to)
   27             TypeSequence      to -> return (TypeInt TagInt, to)
   28             _ -> raiseTypeError $ "(function application)" <+> pretty p
   29         xTy <- typeOf x
   30         if typesUnify [xTy, from]
   31             then return to
   32             else raiseTypeError $ vcat
   33                 [ pretty p
   34                 , "function     :" <+> pretty f
   35                 , "function type:" <+> pretty (TypeFunction from to)
   36                 , "argument     :" <+> pretty x
   37                 , "argument type:" <+> pretty xTy
   38                 ]
   39 
   40 instance SimplifyOp OpImage x where
   41     simplifyOp _ = na "simplifyOp{OpImage}"
   42 
   43 instance Pretty x => Pretty (OpImage x) where
   44     prettyPrec _ (OpImage a b) = "image" <> prettyList prParens "," [a,b]
   45 
   46 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpImage x) where
   47     varSymBreakingDescription (OpImage a b) = JSON.Object $ KM.fromList
   48         [ ("type", JSON.String "OpImage")
   49         , ("children", JSON.Array $ V.fromList
   50             [ varSymBreakingDescription a
   51             , varSymBreakingDescription b
   52             ])
   53         ]