>> Looking at the source code reveals that there is a swap! function that
>> is called each time two elements have to be exchanged.

> Which again only works if we call swap for adjacent elements, no?
> Otherwise the function f() could be defined f(i,j) to resolve this.

Sure.

> Well, but instead of a new function, we would add a new domain?
> I'm not really convinced by this point, because the code has to
> go somewhere.

Yes. But it was just a demonstration how a user can achieve the same
thing without changing library code. This was not specific to your use case.

In fact, the extra domain should have been part of the implementation of
the SortPackage, i.e. the original programmer should have thought about
more general ways to use the code. (Of course, nobody can envision all
future use cases.)

Anyway, the domain implementation is different, because it's not
restricted to bubble sorting. It's just a way to put a hook into a
non-toplevel function. Note that my first demonstration with the ltCount
function was only possible, because the second parameter of bubbleSort!
allowed to hand over exactly such a function. For swap! this wouldn't
have worked. With MyA *any* call to swap! is counted no matter whether
it appears inside or outside of bubbleSort!.

The domain method is like deriving a new class (MyA) from an existing
one (A) in a traditional OO-language and then use the new class (with
the new functionality) all over the place. It's only that here we have a
dependent type. The result type of MyA depends on its input parameter A.
Maybe someone can show me how to do the same thing in Java.

Ralf

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to