constructor name clashes
Steffen Mazanek
steffen.mazanek at gmx.de
Wed Oct 8 22:04:39 EDT 2003
Hello.
>Also, when declaring named fields of a type, such as
>data Data1 = Data1{ok1::Bool}
>data Data2 = Data2{ok2::Bool}
>the field names for different type also have to be unique.
>
>
All function declarations in a module have to be unique. And, e.g., the
data constructor Data1 is a function with type Bool->Data1 and as such
it has to be globally unique as well.
>Isn't that annoying? Keeping all the names unique is no easy task in my
>opinion. Wouldn't it be nice if we can have something similar to structure
>fields in C? Or maybe this is already present and I'm just being ignorant?
>
>
You may have a look at TREX or OHaskell. In TREX (available with Hugs)
and OHaskell
(http://www.math.chalmers.se/~nordland/ohaskell/) you can define records.
For instance, this is a valid OHaskell program:
data Monochrome = Black | White
data Color > Monochrome = Red | Blue
Thereby the data type Color inherits the constructors Black and White
from Monochrome.
Even so, it is not possible to use the same constructors without
establishing a subtype relationship.
AFAIK Haskell98 lacks this possibility. But you can use named fields in
the same declaration
as long as their type remains the same.
Ciao,
Steffen
More information about the Haskell
mailing list