never executed always true always false
1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
2 {-# LANGUAGE UndecidableInstances #-}
3
4 module Conjure.Language.Expression.Op.TwoBars where
5
6 import Conjure.Prelude
7 import Conjure.Language.Expression.Op.Internal.Common
8
9 import qualified Data.Aeson as JSON -- aeson
10 import qualified Data.Aeson.KeyMap as KM
11
12 import qualified Data.Vector as V -- vector
13
14
15 data OpTwoBars x = OpTwoBars x
16 deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
17
18 instance Serialize x => Serialize (OpTwoBars x)
19 instance Hashable x => Hashable (OpTwoBars x)
20 instance ToJSON x => ToJSON (OpTwoBars x) where toJSON = genericToJSON jsonOptions
21 instance FromJSON x => FromJSON (OpTwoBars x) where parseJSON = genericParseJSON jsonOptions
22
23 instance (TypeOf x, Pretty x, Domain () x :< x) => TypeOf (OpTwoBars x) where
24 typeOf p@(OpTwoBars a) = do
25 case project a of
26 Just (_ :: Domain () x) -> return ()
27 Nothing -> do
28 ty <- typeOf a
29 case ty of
30 TypeInt _ -> return ()
31 TypeList{} -> return ()
32 TypeMatrix{} -> return ()
33 TypeSet{} -> return ()
34 TypeMSet{} -> return ()
35 TypeFunction{} -> return ()
36 TypeSequence{} -> return ()
37 TypeRelation{} -> return ()
38 TypePartition{} -> return ()
39 _ -> raiseTypeError $ vcat [ pretty p
40 , "Expected an integer or a collection."
41 , "But got:" <+> pretty ty
42 ]
43 return $ TypeInt TagInt
44
45 instance SimplifyOp OpTwoBars x where
46 simplifyOp _ = na "simplifyOp{OpTwoBars}"
47
48 instance Pretty x => Pretty (OpTwoBars x) where
49 prettyPrec _ (OpTwoBars a) = "|" <> pretty a <> "|"
50
51 instance VarSymBreakingDescription x => VarSymBreakingDescription (OpTwoBars x) where
52 varSymBreakingDescription (OpTwoBars a) = JSON.Object $ KM.fromList
53 [ ("type", JSON.String "OpTwoBars")
54 , ("children", JSON.Array $ V.fromList
55 [ varSymBreakingDescription a
56 ])
57 ]