Betr.: [clean-list] no deriving Eq in Clean?

Paul de Mast demast.pjf@avans.nl
Wed, 07 Jul 2004 10:40:47 +0200


Hello Ben,

You may use Clean genercis for this.

In {Clean 2.1.0}\Libraries\Generics 0.2 you can find GenEq.dcl and GenEq.icl. This module defines an === operator.

If you import this module and define:

derive gEq Cond

you have equality on Con using === (and =/=)

Note that there is a difference between a user defined == and this generic ===

For example:
		Start = (book1==book2, book1===book2)

		:: Book =		{ isbn	:: String
				, title	:: Title
				// other fields*
				}

		instance == Book // user defined equal
			where
			(==) b1 b2	= b1.isbn == b2.isbn

		Derive gEq Book // generic equal

		book1 = {isbn="012345", title = "title"}
		book2 = {isbn="012345", title = "Title"}

This will result in (True, False)

regards,

Paul de Mast

>>> Ben Lippmeier <Ben.Lippmeier@anu.edu.au> 7-7-2004 7:11:14 >>>

Cleaners,

I can live without deriving Read, Show... but not being able to derive 
Eq / == is a real hassle.

If I have a large ADT defined like:

data Cond
    = Friend
    | Foe
    | FriendWithFood
    | FoeWithFood
    | Food
    | Rock
    | FoeMarker
    | Home
    | FoeHome

Is there a better way to define == than:

instance == Cond
where
 (==) :: Cond  Cond      -> Bool
 (==)    Friend Friend   = True
 (==)    Foe    Foe      = True
 ...
 (==)    _      _        = False


???
Even good old C will do this much for you.
It's even worse if the constructors have an airity more than 0.

I could find no mention of Clean giving you any 'free' functions for 
ADTs anywhere in the Clean language report.

I see in Clean2.1Sources/Compiler/frontend/StdCompare.icl that someone 
has done basically what I had to do.. If no one has made a move on 
deriving Eq since this source was written then somone should probably 
add it to the Clean wish list.

Cheers,
Ben.

BTW: There are typos in the page names at
http://www.cs.kun.nl/~clean/CleanExtra/report20/contents.html 
http://www.cs.kun.nl/~clean/CleanExtra/report20/chapters.html 






_______________________________________________
clean-list mailing list
clean-list@cs.kun.nl 
http://www.cs.kun.nl/mailman/listinfo/clean-list