I’m trying to reproduce an Ada generic use case. I can’t quite get Oxygene to do the same thing, and it might not even be possible.
I defined a generic interface for fixed length messaging:
namespace IO.Interfaces.Messaging.Fixed;
interface
type Message = array of Byte;
type Messenger<M> = public interface where M is Message;
procedure Send(msg : M);
procedure Receive(var msg : M);
end;
procedure Dump(msg : Message);
implementation
end.
Now I’m trying to instantiate an interface for 64-byte messages:
namespace IO.Interfaces.Message64;
type Message = array [0 .. 63] of Byte;
type MessengerInterface = IO.Interfaces.Messaging.Fixed.Messenger<Message>;
end.
I can’t get it to work because the static array type IO.Interfaces.Message64.Message isn’t compatible with the open array type IO.Interfaces.Messaging.Fixed.Message.
In Ada, with an unconstrained array type like String, you can either declare a constrained object (variable) or derive a constrained type:
x : String(1 .. 10);
type FixedString is new String(1 .. 10);
y : FixedString;
x and y are both constrained 10-byte variables allocated on the stack.
Is there some way to either declare IO.Interfaces.Messaging.Fixed.Message as a static array with bounds to be determined, or to define IO.Interfaces.Message64.Message as some kind of constrained descendant of IO.Interfaces.Messaging.Fixed.Message?