[Haskell-beginners] data declaration using other type's names?

Brandon Allbery allbery.b at gmail.com
Thu Jun 27 17:37:46 CEST 2013


On Thu, Jun 27, 2013 at 11:24 AM, Patrick Redmond <plredmond at gmail.com>wrote:

> I noticed that ghci lets me do this:
>

Not just ghci, but ghc as well.


> Yay? I can have a simple type with one constructor named the same as the
> type.
> Why is this allowed? Is it useful somehow?
>

It's convenient for pretty much the situation you showed, where the type
constructor and data constructor have the same name. A number of people do
advocate that it not be used, though, because it can be confusing for
people. (Not for the compiler; data and type constructors can't be used in
the same places, it never has trouble keeping straight which is which.)

It might be best to consider this as "there is no good reason to *prevent*
it from happening, from a language standpoint".

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130627/ea0e9cc5/attachment.htm>


More information about the Beginners mailing list