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