You are of course right about the Peano arithmetic (thanks for the info!). However, my type error has a different origin, which I did not mention for the sake of simplicity. The type error originally occurred in an implementation of a double-ended queue:
Basically, the deque domain consists of a prefix and a suffix buffer of 0 to 8 elements and a middle deque of pairs of elements:
Code: Select all
domains
deque{Type} =
empty;
nonEmpty(buffer{Type}, deque{tuple{Type, Type}}, buffer{Type}).
I have noticed that efficient access to the n'th element of the deque can be established if I simply add a field containing the length of the deque:
Code: Select all
domains
raDeque{Type} =
empty;
nonEmpty(buffer{Type}, raDeque{tuple{Type, Type}}, buffer{Type}, positive Length).
The trouble started when I tried to create a catenable version of the random access deque by applying a "bootstrapping" pattern to domain
raDeque{Type}:
Code: Select all
domains
raCatDeque{Type} =
singleton(Type Elem);
nonsingle(raDeque{raCatDeque{Type}}).
The predicates of the
raCatDeque class cannot be based on the predicates of
raDeque, as the length field must be treated differently. In the original
raDeque class, the length of an entry is always counted as 1. However, the entries are now deques, each of which has an individual length.
Trying to create a specialized version of the
raDeque class that correctly calculates the length of entries led me into a nested type mess that the compiler categorically complained about.
I removed everything from my nested type construction that was not necessary to produce the error, renamed domain and functors to make it look intuitive ...that's the way I produced 2).
As you have told, the type error in 2) is correct, and so was the type error in the code of my specialized
raDeque class.
By now I have found a solution that avoids overly complicated nested type constructions. I have added a length field to each buffer field. The increase in memory consumption seems justified, since the additional fields not only make length computation easier, but are also necessary to find the n'th element in O(log N) time (where N is the total number of elements).
Final question: the type layout with prefix/suffix buffer and middle deque is well known, but I have not seen a name for it anywhere. I called it "Isorecursive Pairing Deque". Do you know of a better, perhaps commonly known name?
You do not have the required permissions to view the files attached to this post.