[clean-list] swap from CLAS lib
G.W.M. Vissers
vissers@theochem.kun.nl
Fri, 14 Sep 2001 16:50:09 +0200 (CEST)
Hello,
I was playing around with the CLAS library (again), and noticed that
the swap function class in Clas1.icl only has instances for integers and
unboxed real arrays. Now, the following code works ok:
/////////////////////////////////////////////////////////////////////////
module bla
import StdArray, StdInt
class swap a :: *{# .a} .Int .Int -> .{# .a}
instance swap Int
where
swap x i j
| (i==j) = x
#! (xi, x) = replace x i 0
#! (xj, x) = replace x j xi
= { x & [i] = xj}
instance swap {# Real}
where
swap x i j
| (i==j) = x
#! (xi, x) = replace x i {}
#! (xj, x) = replace x j xi
= { x & [i] = xj}
Start = swap v 2 1
where
v = {1,2,3}
//////////////////////////////////////////////////////////////////////////
So, next I thought it would be nice to add an instance for unboxed integer
arrays, so I added
instance swap {# Int}
where
swap x i j
| (i==j) = x
#! (xi, x) = replace x i {}
#! (xj, x) = replace x j xi
= { x & [i] = xj}
and changed the Start function to
Start = swap v 2 1
where
v = {{1,2,3}, {2,3,4}, {3,4,5}}
Now, the compiler complains:
Error [bla.icl,25,swap ({#})]: swap ({#}) multiply defined symbol
which seems pretty weird to me, because I always thought that integers and
reals were pretty different. So, the question is: what goes wrong here? Is
it possible to use the same class also for swapping rows in an integer
matrix?
Thanks for any pointers,
Gé Vissers