I have a typeclass C.
class C a where
changeProperty :: a -> ??? -> a
C has two (or more) instances
data A = A AProperty X
data B = B BProperty Y
instance C A where
changeProperty (A _ x) ap = A ap x
instance C B where
changeProperty (B _ y) bp = B bp y
bp and ap are of different types. AProperty is only compatible with A and BProperty is only compatible with B. Is it possible to make some for of type signature, or other solution that allows the method changeProperty to accept only these combinations? The only options I have been able to think of either completely separate the methods (in this case into changeAProperty and changeBProperty), or require me to make AProperty and BProperty the same type, which allows for invalid combinations like an A with a BProperty. Ideally I would like to have a Property class of which AProperty and BProperty are instances, but I don't know how to do this and avoid the invalid combinations.
edit: The context of this problem is a script for building molecules for MD simulation. A, B and so on are connections between atoms. For example A would be a bond, containing the parameters for this bond in AProperty and the Atoms that are involved in X. B Would be an angle and BP would contain the parameters related to that angle, Y the Atoms and so on.
data
type has two properties, both having the same type? Change one of them (which one?), or both? – Willem Van Onsem