[Haskell-beginners] Data structure for Propositional Logic formulas

Rustom Mody rustompmody at gmail.com
Thu Oct 13 19:18:50 CEST 2011


On Thu, Oct 13, 2011 at 5:39 PM, Christian Maeder
<Christian.Maeder at dfki.de>wrote:

> Am 13.10.2011 13:24, schrieb Benedict Eastaugh:
>
>  On 13 October 2011 10:12, Christian Maeder<Christian.Maeder at dfki.**de<Christian.Maeder at dfki.de>>
>>  wrote:
>>
>>  Why do most people like duplicate or repeated code?
>>>
>>
>> Hi Christian,
>>
>> I can't speak for most people, but I like my data types to encode the
>> semantics of the domain. In this case, the connectives are logical
>> devices that allow the formation of new well-formed formulae from old
>> ones. I also think it's a mistake to consider them, in their guise as
>> operators, to be any different from negation save in their arity. In
>> my code they are on a par, and any extension to include new n-ary
>> connectives would be straightforward and natural.
>>
>> (There are other unary and binary logical operators which happen not
>> to be listed; I simply included the most commonly used ones, rather
>> than add NAND, XOR, etc. As Daniel pointed out, merely including
>> negation and disjunction allows the formation of a truth-functionally
>> complete system. One can also do this with just NAND or NOR.)
>>
>> The duplication is, ultimately, fairly minor, so doing what you
>> suggest also seems like overkill: it's not as though I'm going to be
>> adding another five or ten connectives any time soon. Your version,
>> while admittedly shorter, makes the code more complex and less
>> readable, for no gain in expressiveness and a very minor improvement
>> in brevity.
>>
>
> I did (and do) not mean to offend you, but reading duplicated code is
> rather hard, because you'll have to take care if it is really the same code
> or if there are minor differences introduced on purpose or by (copy-paste)
> accident.
>
> Cheers Christian
>
>
I was going to write saying that the problem is really with ghc not allowing
'bunched' GADT style defs like so:

data Expr where
     Var  :: String -> Expr
     Neg  :: Expr -> Expr
     Conj, Disj, Cond, BiCond :: Expr -> Expr -> Expr


But now I find it works.  Is this something new in haskell 7??

Of course that does not change the fact that the OP's Expr will need 6
patterns for (total) functions of type Expr -> a.
Christian's will need only 3

The 6 will of course not reduce for the 'bunched' newly supported type
syntax [AFAIK]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111013/edfaf49a/attachment.htm>


More information about the Beginners mailing list