[Haskell-cafe] self-referential data

Maciej Podgurski maciej.podgurski at googlemail.com
Sat Aug 9 21:32:21 EDT 2008

brian wrote:
> On Sat, Aug 9, 2008 at 5:18 PM, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
>> The problem is that BString is not a type, it is a data constructor.
> I know.
>> You could use M.Map BValue BValue, but of course that's probably not
>> what you want either.
> Right. That wouldn't be according to spec either.
>> What's wrong with just using 'String' as the Map key?
> It seems wrong. Yeah, it's just a String, but we're being all abstract
> because that's better practice. It happens that when you parse
> bencoded data, the length of the string is given. Maybe I want to
> store that in BString, too.
> But mainly I want to know how to think about it differently so that I
> know what to do when it comes up again and actually matters.

What about using a type parameter:

data BValue bString = BString     bString
                     | BInteger    Integer
                     | BList       [BValue bString]
                     | BDictionary (Map bString (BValue bString))


More information about the Haskell-Cafe mailing list