[Haskell-cafe] Re: Type classes

Gerrit van den Geest g.vandengeest at students.uu.nl
Mon Mar 20 10:21:50 EST 2006


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 <G.vandenGeest at students.uu.nl> 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).
>
>  
>



More information about the Haskell-Cafe mailing list