[Haskell-cafe] Type classes
Geest, G. van den
G.vandenGeest at students.uu.nl
Mon Mar 20 10:07:23 EST 2006
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 at haskell.org on behalf of Max Vasin
Sent: Mon 3/20/2006 3:46 PM
To: haskell-cafe at 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 at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org//pipermail/haskell-cafe/attachments/20060320/0e858e45/attachment.htm
More information about the Haskell-Cafe
mailing list