I have a type A and an associated type that represents a pair of A, specifically (A, A). I also have a smart constructor for this pair type, which takes a set of A and two values of A. The constructor performs some checks (e.g., ensuring the values belong to the set) and returns the pair of the second and third arguments if the checks pass.
I want to keep track of the set used to create a value of the pair type, but I would like to avoid storing the set in each instance of the pair type. I was considering parameterizing the pair type by the type corresponding to the set of A. Is this feasible in Haskell?
Clarification:
Let’s say there are two lists of integers, [1, 2, 3] and [1, 2, 4]. I have a smart constructor that takes a list of integers, and two integers.
The constructor returns a pair of integers. For example using the first list [1, 2, 3] with 1 and 2, and the second list [1, 2, 4] with 1 and 2, both successfully return the pair (1, 2).
However, in this current setup, the resulting pairs lose the context of which list was used to create them.
Goal: I want to adjust the types such that the resulting pair is distinguishable based on the list that was used to create it, but I don't want to store the list within each value of the adjusted second type.
Update: Possible solution: DataKinds extension seems to do what I need.
Check out Ghosts of Departed Proofs, it's about doing exactly this kind of thing using a generalization of the phantom existential type trick used by ST
.