<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7226.0">
<TITLE>RE: [Haskell-cafe] Type classes</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>
<P><FONT SIZE=2>I suppose you want to define compareEntries like this:<BR>
> compareEntries (Entry x) (Entry y) = compareEntries x y<BR>
<BR>
An option is to just implement it the following way (Haskell98!):<BR>
<BR>
> class DatabaseEntry e where<BR>
> entryLabel :: e -> String<BR>
> formatEntry :: e -> String<BR>
> compareEntries :: e -> e -> Ordering<BR>
><BR>
> data Entry a = Entry a<BR>
><BR>
> instance DatabaseEntry a => DatabaseEntry (Entry a) where<BR>
> entryLabel (Entry e) = entryLabel e<BR>
> formatEntry (Entry e) = formatEntry e<BR>
> compareEntries (Entry x) (Entry y) = compareEntries x y<BR>
<BR>
<BR>
<BR>
Gerrit<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: haskell-cafe-bounces@haskell.org on behalf of Max Vasin<BR>
Sent: Mon 3/20/2006 3:46 PM<BR>
To: haskell-cafe@haskell.org<BR>
Subject: [Haskell-cafe] Type classes<BR>
<BR>
<BR>
Hi!<BR>
<BR>
I'm currently experimenting with a bibliography generation tool for<BR>
LaTeX. It will (if it will be finished) use BibTeX databases but<BR>
bibliography styles will be written in Haskell. I want styles to be<BR>
able to transform database entries into some style specific data type,<BR>
so I define<BR>
<BR>
> class DatabaseEntry e where<BR>
> entryLabel :: e -> String<BR>
> formatEntry :: e -> String<BR>
> compareEntries :: e -> e -> Ordering<BR>
<BR>
Then I define<BR>
<BR>
> data Entry = forall a. (DatabaseEntry a) => Entry a<BR>
<BR>
> instance DatabaseEntry Entry where<BR>
> entryLabel (Entry e) = entryLabel e<BR>
> formatEntry (Entry e) = formatEntry e<BR>
<BR>
How can I define compareEntries for this instance?<BR>
<BR>
--<BR>
WBR,<BR>
Max Vasin.<BR>
<BR>
_______________________________________________<BR>
Haskell-Cafe mailing list<BR>
Haskell-Cafe@haskell.org<BR>
<A HREF="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</A><BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>