From feeb60a196f1458ef5aa40833a8154152057bb85 Mon Sep 17 00:00:00 2001 From: Sibi Date: Thu, 7 Aug 2014 02:01:47 +0530 Subject: [PATCH] Making the truthTable function to generate string without color as it seems the sensible default. (although it's debatable) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added a function truthTablewithColor which will handle the coloured situations. The primary motivation was for cases something like this: import Data.Logic.Propositional import System.IO p = Variable (Var 'p') q = Variable (Var 'q') exp1 = (Negation p) `Disjunction` q exp1T = truthTable exp1 main = writeFile "Table.txt" exp1T The output produced earlier was like this: p q | (¬p ∨ q) -------------- T T | T T F | F F T | T F F | T After the patch, it will produce like this: p q | (¬p ∨ q) -------------- T T | T T F | F F T | T F F | T --- src/Data/Logic/Propositional/Tables.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Data/Logic/Propositional/Tables.hs b/src/Data/Logic/Propositional/Tables.hs index b7af21d..000ebb1 100644 --- a/src/Data/Logic/Propositional/Tables.hs +++ b/src/Data/Logic/Propositional/Tables.hs @@ -9,6 +9,7 @@ module Data.Logic.Propositional.Tables , colourBool , showBool , truthTable + , truthTablewithColor , truthTableP ) where @@ -21,7 +22,12 @@ type Printer = (Expr -> String, Bool -> String) -- | The 'truthTable' function produces a truth table for the given expression. truthTable :: Expr -> String -truthTable = truthTableP (show, colourBool) +truthTable = truthTableP (show, showBool) + +-- | This 'truthTablewithColor' function produces a coloured truth +-- table with green for 'True' and red for 'False' +truthTablewithColor :: Expr -> String +truthTablewithColor = 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 @@ -47,10 +53,12 @@ showBool :: Bool -> String showBool True = "T" showBool False = "F" --- | Prints a green @T@ for 'True' and a red @F@ for 'False'. This is used when --- producing a string representation of a truth table with 'truthTable'. It can --- also be used as (as the second component of a 'Printer' pair) as an argument --- to the configurable 'truthTableP' function. +-- | Prints a green @T@ for 'True' and a red @F@ for 'False'. This is +-- used when producing a string representation of a truth table with +-- 'truthTablewithColor'. It can also be used as (as the second +-- component of a 'Printer' pair) as an argument to the configurable +-- 'truthTableP' function. colourBool :: Bool -> String colourBool True = show . green . text $ "T" colourBool False = show . red . text $ "F" +