[clean-list] Re: no deriving Eq in Clean? / toString badness
Ben Lippmeier
Ben.Lippmeier@anu.edu.au
Thu, 08 Jul 2004 15:52:59 +1000
Paul,
Thanks for answering my question.
It turns out that the Linux binary distribution I got from the Clean
web-site did not include the Generics library. I had to download the
Windows version and copy the files across. I also had to grab the
StdGeneric.icl (.dcl) from the Windows distribution and copy it to
$(clean)/stdenv for this to work..
Then it turns out that you have to provide the instance for (==) anyway
otherwise utility functions (lookup, find, .. ) stop working.. my code
now contains lots of snippets like the following...
derive gEq SomeType
instance == SomeType where
(==) a b = a === b
It's curious that you would choose to use (===) over (==) for the more
common equality (at least from the programmers perspective) .. though I
suppose that generics were added after the old (==) was in common use.
------------------
Continuing on the "toInt badness" thread,
("'" +++ toString [1, 2, 3] +++ "'") produces simply "''"
in StdList.icl
instance toString [x] | toChar x
As toChar for lists does a direct ascii conversion, you end up with a
set of control characters instead of what you intended. .. _even though_
(toString 3) gives you the 'correct' answer "3"..
.. perhaps someone should take note of "the principle of least surprise"
? :)
.. it's a good thing I REALLY want to write this program in Clean.. a
lesser man might have given up by now.
Ben.
------------------------
Paul de Mast wrote:
>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.
>
>
>
>