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