[Haskell-cafe] Type classes

Matthias Fischmann fis at wiwi.hu-berlin.de
Mon Mar 20 10:13:19 EST 2006



see my discussion a few moments ago, in particular my posting

  http://www.haskell.org/pipermail/haskell-cafe/2006-March/014981.html

as you by now already know from this thread, the link tells you that
the only possible solution is to turn the two entries to be compared
into something of the same type, which can only be done with another
type class.  i am using 'Show' for now and compare the strings,
because it's really simple and i don't care about performance at this
stage of the project.  might bite me later, though.

cheers,
matthias



On Mon, Mar 20, 2006 at 05:46:43PM +0300, Max Vasin wrote:
> To: haskell-cafe at haskell.org
> From: Max Vasin <max-appolo at mail.ru>
> Date: Mon, 20 Mar 2006 17:46:43 +0300
> 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

-- 
Institute of Information Systems, Humboldt-Universitaet zu Berlin

web:      http://www.wiwi.hu-berlin.de/~fis/
e-mail:   fis at wiwi.hu-berlin.de
tel:      +49 30 2093-5742
fax:      +49 30 2093-5741
office:   Spandauer Strasse 1, R.324, 10178 Berlin, Germany
pgp:      AD67 CF64 7BB4 3B9A 6F25  0996 4D73 F1FD 8D32 9BAA


More information about the Haskell-Cafe mailing list