[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rather, DSSLs increase modularity, productivity



Shriram Krishnamurthi wrote:

>Christopher, my question is not so much to explore the theoretical
>value of Curl's system.  But theory *is* useful because it helps us
>understand things better.  I've been trying to understand Curl's type
>system for a while now and I must admit, it's hard to form a model of
>it.  I wonder if in fact the type system really is *defined* by the
>compiler, as in, "if the compiler's combination of algorithms can
>establish this type, then the expression has this type" -- where the
>set of algorithms can change next week.
>
>Re. my example, you made a claim about type checking that either (i) I
>don't understand or (ii) seems to have been false.  In the short
>snippet I gave you, there is a type-annotated variable that (a) can
>flag errors at run-time only, and (b) requires checks at run-time.  As
>I understand it, this clearly runs counter to your initial claims.
>Ergo, the two options I see are (i) and (ii).
>
When I say 'variable', I am referring to the named binding ('x' in this
case) not the value to which it refers.  Curl statically checks
assignments and uses of bindings.  Since the binding 'y' has no type
annotation, it is essentially not checked, even though it refers to the
same object as 'x'.

>>Curl's type system is probably not all that interesting from a 
>>theoretical standpoint but it does allow the programmer to choose 
>>between dynamic and static programming styles as they see fit.
>>    
>Again, I've heard this claim repeatedly now, and I still can't quite
>tell what it means.  Perhaps you could tell us how Curl provides this
>choice in an *interesting* way?  I thought it might be because the
>compiler's smarts meant once a check was performed once in a body, it
>flowed through to other values in the body.  But your own example
>rejects that possibility:

I am not actually claiming that the compiler is all that smart.  In
fact, it really only does fairly simple optimizations.  Curl is intended
to work well in the domain of client-side computing, in which the
program code is delivered to the client from the server and compiled to
machine code on the fly.  It was important to us that we make it
possible to generate relatively efficient code quickly, so minimize the
time an end-user may have to spend waiting for freshly downloaded
content.  One technique for achieving this was to put off compilation of
methods until they are called.  If a program never invokes method 'foo',
it will not be compiled, but code that uses foo still needs to know its
type signature.  Clearly that signature cannot be inferred from the
method body in this model, so it must be explicitly declared.

Curl's type system can be thought of as an extension of Java and C#s.
Like both of those languages, Curl has class types derived from a common
Object class, and primitive numeric types.  Curl adds to this closures
(which we call anonymous procs),  multiple inheritance,  parameterized
classes, quantity types (a magnitude combined with standard dimensions
time, distance, mass, etc), and the abstract 'any' type, which I have 
already briefly described.  There is also a type annotation to indicate 
whether a reference binding is intended to  allow a null value.

>>     {define-class A}
>>     {define-class B {inherits A} {method {b}}}
>>      let x:A = {B}
>>      let y = x
>>      {y.b} || ok
>>      {x.b} || error, no member 'b' defined in 'A'
>>    
>>
>
>Even though x has a type annotation, and x clearly flows to y, y does
>not inherit the type annotation.  That seems really strange.  You (and
>other Curl people) have said that Curl "infers" types in a few
>specialized cases (and I do recall some examples of it over local
>scopes back when I tried out Curl), but this is about as natural a
>case as any that I could imagine! 
>
Yes, you are absolutely right.  In fact, we would like to make such a
change in a future version of the language.  Of course, this would not
be entirely backwards compatible since it would outlaw behaviors that
are currently allowed.

- Christopher