[Haskell-beginners] data type design question
Tillmann Rendel
rendel at daimi.au.dk
Wed Jul 30 08:10:07 EDT 2008
Hi Markus,
Markus Barenhoff wrote:
> I have written a parsec parser for reading a marshallaled dataformat.
>
> The returned data structure is based on the following data type:
>
>> data T = TString String
>> | TInt Integer
>> | TList [TorrentT]
>> | TDict [(TorrentT, TorrentT)]
>
> I think TString and TInt are clear. The elements of a TList always have
> the same "type" (same constructor). The TDict is a dictionary where the
> key is always a TString but the value can be of any of the other "types",
> even in the same dictionary. F.e the key "foo" may map to a TInt while the
> key "bar" maps to another TDict.
Maybe something like
data T = TString String
| TInt Integer
| TStringList [String]
| TIntList [Integer]
| TDict [(String, T)]
would work.
Tillmann
More information about the Beginners
mailing list