Re: labelled fields
Steffen wrote I need something like data Type = TCon String {lmtc::Maybe String} ... but this does not seem to be possible. Instead I have to waste identifiers: data Type = TCon {senseless::String,lmtc::Maybe String} ... Why? Are there any formal reasons against the above declaration? Clearly it's arguable, since SML allows general record types. My SML syntax is rusty but I think you could write: datatype ty = ty string {lmtc : string option} or indeed use {lmtc : string option} just like a type. I don't think [EMAIL PROTECTED] is suitable for lengthy discussions of the merits of SML versus Haskell or vice-versa, so I will state my view and leave it at that: (1) the Haskell approach costs you slightly more typing. (2) on the other hand the error messages are slightly better, since if you type TCon {sensless = foo} the compiler should spot immediately that sensless has no place in a TCon, while in ML the compiler will have to say something like Expecting a {senseless :: String}, found a {sensless :: String}, which leaves you to work out what it is about the context that requires a {senseless :: String} (3) the Haskell approach allows several constructors to have the same field name, for example data Ty1 = TCon1 {lmtc :: Maybe String} | TCon2 {lmtc :: Maybe String, extraField :: String} and you then have a function lmtc :: Ty1 - Maybe String which works for all constructors having the lmtc field. (4) Haskell will fill in undefined fields, with values that give error messages if you try to look at them. Which you prefer is entirely up to you. None of the above points are terribly important. I personally prefer the Haskell approach, but not by much. ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: labelled fields
Ok, I had missed something: I can write instead: data Type = TCon String (Maybe String) ... and declare a function lmtc lmtc (TCon _ x) = x ... But why not allow syntactic sugar? Sorry, Steffen -- Steffen Mazanek - www.steffen-mazanek.de - GPG: 791F DCB3 Haskell, that's where I just curry until fail, unwords any error, drop all undefined, maybe break, otherwise in sequence span isControl and take max $, id: (d:[]) ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: labelled fields
...it's also not the same...for instance, in this new version you cannot say: foo = bar { thing = Nothing } which you could say given: data Foo = Foo String { thing :: Maybe String } I'd guess that this is disallowed just for consistency. I think it would just be too many rules to keep track of something with a combination of multiple named fields and multiple unnamed fields. I don't know though... You can always give them names like _foo1 etc., in which case ghc probably won't warn about them, as is the case with methods whose names begin with underscores... - Hal -- Hal Daume III | [EMAIL PROTECTED] Arrest this man, he talks in maths. | www.isi.edu/~hdaume On Tue, 3 Jun 2003, Steffen Mazanek wrote: Ok, I had missed something: I can write instead: data Type = TCon String (Maybe String) ... and declare a function lmtc lmtc (TCon _ x) = x ... But why not allow syntactic sugar? Sorry, Steffen -- Steffen Mazanek - www.steffen-mazanek.de - GPG: 791F DCB3 Haskell, that's where I just curry until fail, unwords any error, drop all undefined, maybe break, otherwise in sequence span isControl and take max $, id: (d:[]) ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell
Re: labelled fields in ghc-2.04
| data X = A {a :: Int} | B {a :: Int} | -- | test2.lhs:2: | Conflicting definitions for: `a' | Defined at test2.lhs:3 | Defined at test2.lhs:3 Embarassing, but all too true. There's really no workaround for this. GHC 2.04 is stupidly unable to have the same record field in two different constructors of a data type. I've fixed my copy. Everyone: pls let me know if this bug is holding you up. If so I'll put out a revised version. Simon | From: Meurig Sage [EMAIL PROTECTED] | Date: Thu, 12 Jun 1997 20:31:44 +0100 | This bug was mentioned during ghc-2.03's time. I thought it had been | fixed since. But the following code still does not compile in ghc-2.04: | | -- | data X = A {a :: Int} | B {a :: Int} | -- | test2.lhs:2: | Conflicting definitions for: `a' | Defined at test2.lhs:3 | Defined at test2.lhs:3 | | | Compilation had errors | -- | -- | Meurig Sage | Dept of Computing Science | University of Glasgow | http://www.dcs.gla.ac.uk/~meurig | mailto:[EMAIL PROTECTED]