Use of singleton return types 
Author Message
 Use of singleton return types

In my free hours I am toying around with a small term rewriting system,
where I have "discovered" this idiomlet (heavily simplified):

define abstract class <term>(<object>)

define abstract class <const-term>(<term>)

define abstract class <var-term>(<term>)

define abstract class <let-term>(<term>)


// Now I want to rewrite general terms to a subset of the term constructors
getting a
// normal form:

define generic normal(t :: <term>) => NF :: <term>;

// specialized methods come here...
// then in the rewriting of "let binding = <term1> in <term2>"
// I have to reinterpret <term1> as a "named-term" which has some specific
// requirements, so that the rewriting does not always succeed:

define generic named-term(t :: <term>) => (NT :: <term>, success ::

// Now, <var-term> is always a named-term, so I can write:

define method named-term(v :: <var-term>)
                                => (NT :: <var-term>, success :: #t.singleton)
        values(v, #t)

// etc.

Look at the type of the success result parameter. It completely determines
that result component. This works well with the ADTR I work with (besides
that the compiler comes into an infinite loop if I attempt to return #f,
where a #t.singleton type is declared :-)

Here come my questions:

a) besides being an excellent way of documenting the result, can modern
compilers use this kind of return value subtyping (with singleton) in any
way? (HD, GD?)

b) Taking this idea further one could introduce argument-dependent result
types like this:

define method named-term(v :: <var-term>)
                                => (NT :: v.singleton, success :: #t.singleton)
        values(v, #t)

Here the compiler would know almost anything about the invocation of
named-term on a (sure) <var-term> so after calling named-term, it could
safely discard the result. (Why? Because named-term need not terminate, or
could perform a side effect)

I heard about a similar attempt to introduce parametric polymorphism by
means of argument-dependent result types, can somebody comment on how far
these ideas have moved on?

Just wondering...


Mon, 21 Jan 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Error using the *? return type

2. 'Singleton' and Null Limited Types

3. Fun with singletons' singleton classes

4. Extending Python with C++ singleton pattern using boost python lib

5. Extending Python with C++ singleton pattern using boost pytho n lib

6. tcl objc type: args uses only string of own type

7. using sizeof do get the number of bytes used by a type

8. dll return type?

9. Array as return type for handler?

10. Translating VB return type STRING

11. Illegal Return Type problem

12. Illegal Return Type or attribute


Powered by phpBB® Forum Software