<div dir="ltr">Hello there,<div><br></div><div>I've been thinking on different approaches to constraint particular functions to a particular constructor of an ADT in order to reduce representation of invalid states. Say for example I've this types:</div><div><br></div><div><font face="monospace, monospace">data Address = Address { ... }</font></div><div><font face="monospace, monospace">newtype Email = Email String</font></div><div><font face="monospace, monospace">data Package = Package { ... }</font></div><div><font face="monospace, monospace">data EmailMsg = EmailMsg { ... }</font></div><div><br></div><div><font face="monospace, monospace">data User </font></div><div><font face="monospace, monospace">  = RealUser Address</font></div><div><font face="monospace, monospace">   | VirtualUser Email</font></div><div><br></div><div>And I would like to implement two functions:</div><div><br></div><div><font face="monospace, monospace">deliverPackage :: User -> Package -> IO Bool</font></div><div><font face="monospace, monospace">sendEmail :: User -> EmailMsg -> IO ()</font></div><div><br></div><div>I would like to constraint both <font face="monospace, monospace">deliverPackage</font> and <font face="monospace, monospace">sendEmail</font> to receive only the semantically correct constructor of <font face="monospace, monospace">User</font>. </div><div><br></div><div>I know of an approach I could use, that is wrapping each constructor in it's own<font face="monospace, monospace"> newtype</font>, and create some smart constructor that way, that approach works, but I find it rather verbose. </div><div><br></div><div>Is there any other well known approach to deal with this scenarios?</div></div>