never executed always true always false
    1 {-# LANGUAGE DeriveGeneric, DeriveDataTypeable, DeriveFunctor, DeriveTraversable, DeriveFoldable #-}
    2 
    3 module Conjure.Language.Expression.Op.Table 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 OpTable x = OpTable x x
   15     deriving (Eq, Ord, Show, Data, Functor, Traversable, Foldable, Typeable, Generic)
   16 
   17 instance Serialize x => Serialize (OpTable x)
   18 instance Hashable  x => Hashable  (OpTable x)
   19 instance ToJSON    x => ToJSON    (OpTable x) where toJSON = genericToJSON jsonOptions
   20 instance FromJSON  x => FromJSON  (OpTable x) where parseJSON = genericParseJSON jsonOptions
   21 
   22 instance (TypeOf x, Pretty x) => TypeOf (OpTable x) where
   23     typeOf p@(OpTable vars table) = do
   24         tyVars <- typeOf vars
   25         tyTable <- typeOf table
   26         let
   27             tyError = raiseTypeError $ vcat [ pretty p
   28                                             , pretty vars <+> "has type" <+> pretty tyVars
   29                                             , pretty table <+> "has type" <+> pretty tyTable
   30                                             ]
   31             listLike (TypeList TypeInt{}) = return ()
   32             listLike (TypeMatrix _ TypeInt{}) = return ()
   33             listLike _ = tyError
   34         listLike tyVars
   35         case tyTable of
   36             TypeList inner -> listLike inner
   37             TypeMatrix _ inner -> listLike inner
   38             _ -> tyError
   39         return TypeBool
   40 
   41 instance SimplifyOp OpTable x where
   42     simplifyOp _ = na "simplifyOp{OpTable}"
   43 
   44 instance Pretty x => Pretty (OpTable x) where
   45     prettyPrec _ (OpTable a b) = "table" <> prettyList prParens "," [a, b]
   46 
   47 instance (VarSymBreakingDescription x, ExpressionLike x) => VarSymBreakingDescription (OpTable x) where
   48     varSymBreakingDescription (OpTable a b) = JSON.Object $ KM.fromList
   49         [ ("type", JSON.String "OpTable")
   50         , ("children", JSON.Array $ V.fromList [varSymBreakingDescription a, varSymBreakingDescription b])
   51         , ("symmetricChildren", JSON.Bool True)
   52         ]