Hi, all. I'm a newbie to Haskell so please bear with me if my questions sound silly. In coding Haskell, I feel very inconvenient that the name of data constructors for different types have to be different. 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. 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? I know that we can use modules to introduce name spaces. But still, this is quite cumbersome. Thanks! Ben. This message is intended only for the addressee and may contain information that is confidential or privileged. Unauthorized use is strictly prohibited and may be unlawful. If you are not the intended recipient, or the person responsible for delivering to the intended recipient, you should not read, copy, disclose or otherwise use this message, except for the purpose of delivery to the addressee. If you have received this email in error, please delete and advise us immediately.
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
participants (2)
-
Ben_Yu@asc.aon.com -
Steffen Mazanek