
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