On Tue, 4 Apr 2000 [EMAIL PROTECTED] wrote:

> Well Gisle...
> 
> REBOL is currently an interpreted language. This means that all of
> the various language processing, including type-checking, is done at
> runtime. Under these circumstances, type-checking is a luxury, only
> done to catch errors. Since any errors in the function return type
> are localized to the function, there are often more efficient ways
> to deal with them than declarative type-checking. Regardless, these
> types of errors should be handled within the function before return;
> any error that results from the return itself would need handling by
> the caller of the function.
> 
> For functional languages in general, strong typing is typically done
> a little differently than in procedural languages. Although function
> parameters are typed, function return types are usually determined
> by inference. Type inference allows strong typing without requiring
> the programmer to specify return types that the compiler is perfectly
> capable of figuring out for itself. REBOL already lets you specify
> enough information to perform type inference, but it currently doesn't
> do type inference because of the runtime overhead this would cause in
> an interpreter. A type inferencer for REBOL would be possible to do,
> but would be a better preliminary testing tool than a runtime tester.
> 
> In general, declarative type checking only makes sense when the types
> are checked before runtime. Runtime checking should only be done by
> code that can recover from any errors, and usually close to the source
> of the error (in the function) rather than distributed all over the
> place in calling functions. An exception to this is functions that
> primarily run code passed to them (language functions like foreach),
> which should handle any errors internal to the function, but pass on
> ones caused by the code passed to them. None of these cases are helped
> by declarative return type checking.


OK, good points! However, I can't quite see how you can make a type
inferencer (as a preliminary testing tool, just for the purpose of
spotting stupid mistakes early) when functions can return values of
different types from one call to the next given the same argument types.
Example:

>> ? find
Finds a value in a series and returns the series at the start of it.
Arguments:
    series --  (series port bitset)
    value --  (any-type)
Refinements:
        .
        .
        .

What the documentation doesn't say here is that find can also return the
value none if it doesn't find what it's looking for.
How is it possible to infer this when 'find is native?
I can see it's possible when you have the source of the function and
the source of all functions called by it and so on, but this is never the
case in rebol is it?
How can I make a script that allow me to check this sort of thing?
It would be especially helpful in cases like 'find, since it could check
if I handle all possible return types.

Elan's idea of being able to optionally specify return types of a
function would be nice provided that all natives that can
return more than one type used it.

Maybe I'm missing something? Any comments?

Gisle


Reply via email to