
On Sun, Dec 07, 2014 at 09:37:11AM +0000, Derek McLoughlin wrote:
Hi,
Record types usually have a single constructor. I've even seen blog posts that suggest that they must have a single constructor. However, multiple constructors are allowed:
data Employee = RegularEmployee { name :: String } | Supervisor { name :: String, salesTarget :: Double } Manager { name :: String, salesTarget :: Double budget :: Double }
I don't see this used much in Haskell code - either in explanatory books/tutorials or in code I've examined on GitHub. Are there drawbacks to using multiple constructors in this way?
I think you might see it fairly frequently in users of command line parser libs, e.g. optparse-applicative[^1], for accepting sub-commands. /M [^1]: http://hackage.haskell.org/package/optparse-applicative -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus@therning.org jabber: magnus@therning.org twitter: magthe http://therning.org/magnus Perl is another example of filling a tiny, short-term need, and then being a real problem in the longer term. -- Alan Kay