
I suppose you want to define compareEntries like this:
compareEntries (Entry x) (Entry y) = compareEntries x y
An option is to just implement it the following way (Haskell98!):
class DatabaseEntry e where entryLabel :: e -> String formatEntry :: e -> String compareEntries :: e -> e -> Ordering
data Entry a = Entry a
instance DatabaseEntry a => DatabaseEntry (Entry a) where entryLabel (Entry e) = entryLabel e formatEntry (Entry e) = formatEntry e compareEntries (Entry x) (Entry y) = compareEntries x y
Gerrit -----Original Message----- From: haskell-cafe-bounces@haskell.org on behalf of Max Vasin Sent: Mon 3/20/2006 3:46 PM To: haskell-cafe@haskell.org Subject: [Haskell-cafe] Type classes Hi! I'm currently experimenting with a bibliography generation tool for LaTeX. It will (if it will be finished) use BibTeX databases but bibliography styles will be written in Haskell. I want styles to be able to transform database entries into some style specific data type, so I define
class DatabaseEntry e where entryLabel :: e -> String formatEntry :: e -> String compareEntries :: e -> e -> Ordering
Then I define
data Entry = forall a. (DatabaseEntry a) => Entry a
instance DatabaseEntry Entry where entryLabel (Entry e) = entryLabel e formatEntry (Entry e) = formatEntry e
How can I define compareEntries for this instance? -- WBR, Max Vasin. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

"Geest," == Geest, G van den
writes:
Geest,> I suppose you want to define compareEntries like this:
compareEntries (Entry x) (Entry y) = compareEntries x y
Geest,> An option is to just implement it the following way Geest,> (Haskell98!):
class DatabaseEntry e where entryLabel :: e -> String formatEntry :: e -> String compareEntries :: e -> e -> Ordering
data Entry a = Entry a
No. I don't want that. The database parsing function returns Map.Map String Entry but entries can of different types (and these type vary over styles). -- WBR, Max Vasin.

Then you should produce 'some canonical representation for database entries suited for comparison', like Stefan mentioned. For example:
data Entry = forall a. (DatabaseEntry a) => Entry a
instance DatabaseEntry Entry where entryLabel (Entry e) = entryLabel e formatEntry (Entry e) = formatEntry e compareEntries (Entry x) (Entry y) = compare (entryLabel x) (entryLabel y)
Gerrit Max Vasin wrote:
"Geest," == Geest, G van den
writes: Geest,> I suppose you want to define compareEntries like this:
compareEntries (Entry x) (Entry y) = compareEntries x y
Geest,> An option is to just implement it the following way Geest,> (Haskell98!):
class DatabaseEntry e where entryLabel :: e -> String formatEntry :: e -> String compareEntries :: e -> e -> Ordering
data Entry a = Entry a
No. I don't want that. The database parsing function returns Map.Map String Entry but entries can of different types (and these type vary over styles).
participants (3)
-
Geest, G. van den
-
Gerrit van den Geest
-
Max Vasin