I was wondering if it is possible (I guess it is :) ) to have recursive sum type where we have a value of type X on every level, but somehow restrict ourselves that on every level of recursion we have distinct value of X?
For example, if I have
data MachineType = Worker | Flyer | Digger | Observer | Attacker
data Machine = Single MachineType | Multi MachineType Machine
type system would allow me to construct Machine with following type:
Multi Worker (Multi Worker (Single Worker))
but I want this to be restricted, so that only different MachineType-s are allowed.
Is there a way to encode this in type system?
You can just point me in the right direction, as I kinda don't know what to google :) (haskell set-like recursive sum types?)