On 22 March 2010 01:44, Jonathan S. Shapiro <[email protected]> wrote:
> Michal:
>
> I have a feeling there is a good question in here, but I can't make
> out what the example is saying, partly because I don't seem to
> recognize what language it is in.
It's a kind of pseudocode using the syntax I was taking about in another thread.
Let me explain
>> Still I wonder how do you express extensions in terms of these BitC objects.
>>
>> Take these for example:
>>
This defines an interface of an object. The object is of type :type
and is referred to as 'self' as is the case in many OO languages.
>> interface Ordered [:type] {
I require that it implements the comparison operator.
>>
>> require <=>: [:type] : :numeric
I also want that the operator has certain properties which are described below.
The utility of the below code can range from mere comment to something
that is checked statically on classes that implement the interface.
This particular assertion should be possible to check on not overly
complex methods but I did not delve into details how that would be
done.
>>
>> assert ( sgn(self.<=> other) == -sgn(other.<=>self) )
>> assert ( ((self.<=> other) == 0 ) || (self != other)
Below additional operators are defined using the comparison operator above.
They should be available for any class that implement the comparison operator.
>>
>> def >: [other :type] : :bool { (self.<=> other) > 0 }
>> def <
>> def <=
>> def >=
>> }
>>
This is a super-interface of the above.
As the above includes quite a bit of information it is practical to
allow for constructing super-interfaces.
>> interface Enumerable [:type] {
>> include Ordered
>> require succ: :type
>> assert ( succ > self )
>> }
>>
Here a class integer says to implement Enumerable which in turn means
it implements Ordered which requires to have <=> and succ and makes
available <, <=, >, >=.
>> integer {
>>
>> implements Enumerable
>>
>> def <=>[other:integer] { self - other}
This definition of succ with the above requirement that succ(n) > n
would work for integers represented as strings of digits or similar,
not for words(dwords, qwords). For words succ could possibly cause
exception if adding 1 causes overflow. The string representation could
overflow available memory so the behaviour is generally the same but
it is more likely to happen with fixed precision. I am not quite sure
the correctness of the definition could be checked in this case,
though.
>> def succ { self + 1 }
>>
>> }
>>
The Enumerable does not guarantee nice semantics in all cases. For
example, it does not guarantee that a range is finite. Given a
potentially unbound object like string or fraction you could define a
range <a,b> where succ(... (succ(a))) never reaches b.
But the range does raise another issue of syntax.
If I wanted a range of Enumerables how do I do that?
It is a type parameter but I want the parameter to be one that
implements Enumerable.
Perhaps in the type system of BitC I just accept any type and then
instantiate an Enumerable of the actual parameter in the code and it
would fail if it is not compatible.
Thanks
Michal
Thanks
Michal
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev