{-# OPTIONS_HADDOCK hide #-}moduleData.Logic.Propositional.Tables(Printer,colourBool,showBool,truthTable,truthTableP)whereimportData.Logic.Propositional.CoreimportData.Map(fold)importText.PrettyPrint.ANSI.Leijen(green,text,red)typePrinter=(Expr->String,Bool->String)-- | The 'truthTable' function produces a truth table for the given expression.truthTable::Expr->StringtruthTable=truthTableP(show,colourBool)-- | The 'truthTableP' is a configurable version of 'truthTable' which allows a-- printer function to be selected, so for example one can print ASCII truth-- tables by passing 'showAscii' to 'truthTableP' instead of 'show'.truthTableP::Printer->Expr->StringtruthTableP(expPrinter,boolPrinter)expr=unlines[header,separator,body]whereheader=unwordsvs++" | "++expPrinterexprbody=init.unlines$map(showAssignmentboolPrinterexpr)asseparator=concat$replicatesepLength"-"sepLength=lengthvs*2+length(expPrinterexpr)+2as=assignmentsexprvs=variablesexprshowAssignment::(Bool->String)->Expr->Mapping->StringshowAssignmentprinterexpra=showVarValues++" | "++showExprValuewhereshowVarValues=unwords$fold((:).printer)[]ashowExprValue=printer$interpretexprashowBool::Bool->StringshowBoolTrue="T"showBoolFalse="F"colourBool::Bool->StringcolourBoolTrue=show.green.text$"T"colourBoolFalse=show.red.text$"F"