{-# LANGUAGE DeriveDataTypeable, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}moduleData.Logic.Types.PropositionalwhereimportData.Generics(Data,Typeable)importData.Logic.Classes.Combine(Combinable(..),Combination(..),BinOp(..))importData.Logic.Classes.Constants(Constants(..),asBool)importqualifiedData.Logic.Classes.FormulaasCimportData.Logic.Classes.Literal(Literal(..))importData.Logic.Classes.Negate(Negatable(..))importData.Logic.Classes.Pretty(Pretty(pretty),HasFixity(..),topFixity)importData.Logic.Classes.Propositional(PropositionalFormula(..),prettyPropositional,fixityPropositional,foldAtomsPropositional,mapAtomsPropositional)-- | The range of a formula is {True, False} when it has no free variables.dataFormulaatom=Combine(Combination(Formulaatom))|Atomatom|T|F-- Note that a derived Eq instance is not going to tell us that-- a&b is equal to b&a, let alone that ~(a&b) equals (~a)|(~b).deriving(Eq,Ord,Data,Typeable)instanceNegatable(Formulaatom)wherenegatePrivatex=Combine((:~:)x)foldNegationnormalinverted(Combine((:~:)x))=foldNegationinvertednormalxfoldNegationnormal_x=normalxinstance(Ordatom)=>Combinable(Formulaatom)wherex.<=>.y=Combine(BinOpx(:<=>:)y)x.=>.y=Combine(BinOpx(:=>:)y)x.|.y=Combine(BinOpx(:|:)y)x.&.y=Combine(BinOpx(:&:)y)instanceConstants(Formulaatom)wherefromBoolTrue=TfromBoolFalse=FasBoolT=JustTrueasBoolF=JustFalseasBool_=Nothinginstance(Prettyatom,HasFixityatom,Ordatom)=>C.Formula(Formulaatom)atomwhereatomic=AtomfoldAtoms=foldAtomsPropositionalmapAtoms=mapAtomsPropositionalinstance(Prettyatom,HasFixityatom,Ordatom)=>Literal(Formulaatom)atomwherefoldLiteralnegtfatformula=caseformulaofCombine((:~:)p)->negpCombine_->error("Unexpected literal: "++show(prettyformula))Atomx->atxT->tfTrueF->tfFalseinstance(C.Formula(Formulaatom)atom,Prettyatom,HasFixityatom,Ordatom)=>PropositionalFormula(Formulaatom)atomwherefoldPropositionalcotfatformula=caseformulaofCombinex->coxAtomx->atxT->tfTrueF->tfFalseinstance(Prettyatom,HasFixityatom,Ordatom)=>Pretty(Formulaatom)wherepretty=prettyPropositionalprettytopFixityinstance(Prettyatom,HasFixityatom,Ordatom)=>HasFixity(Formulaatom)wherefixity=fixityPropositional