Smatchcube's website 🌍

Exercise 2.85

We works we the tower of type: rational -> scheme-number -> complex\ Let’s just define the project operation for complex numbers, it’s not really useful to project a real to a rational:

Now we can define the drop procedure, it just project the object until it’s no longer equal to the original object (using the equ? procedure we defined earlier for the equality test).

Now we can add call the drop procedure just before returning the result in apply-generic, we must be careful to not call drop when we are using raise or equ? because they are also generic operations in my implementation and that a raised number should not be dropped. Predicates should also not be droped as they are not tagged in my implementation.

Taking the example from the book, let’s add \(2 + 3i\) to \(4 - 3i\):

As expected the result (complex rectangle 6 . 0) is simplified to 6.