I’m doing some stuff with SAT, and I want to have both “and” and “or” clauses.
type AndClause = [Literal]
type OrClause = [Literal]
But I’m running into problems when I use them:
instance Satisfiable AndClause where ...
instance Satisfiable OrClause where ...
Gives me “Duplicate instance declarations.” They are types, not data or type constructors, so I don’t think I can use newtype to do what I want. Is there any solution?
The problem is that you seem to want two conflicting things at once:
Based on the domain, I think you certainly don’t want to be using type synonyms, and that you do want actual new types (with accompanying type constructors). If
AndClauseis a synonym for[Literal], andOrClauseis a synonym for[Literal], then by the transitive property,AndClauseandOrClauseare mutually synonymous. Hence, the compiler has no reason to differentiate between them (thus, there can be no polymorphism).What you really want are two different types that behave differently, for which
newtypewill do just fine:But, an even better idea might be to make this an algebraic data type:
(Note that I’m typing this away from a compiler, but it should basically be right).