Hi,

I've been doing some thinking about the treatment of nil in a
statically typed version of Clojure.

It occurs to me that nil is significantly different to Java's null
reference, which
is almost a Bottom type.

Java's null is a subtype of any reference type.
Clojure's nil is just nil, subtype to nothing except itself.

To accomodate this, nil should be implicitly added to the result
type of any interaction with Java via interop.

(Union syntax: (U x0 .. xn) is the union of types x0..nx)

<expr> :- <type of expr>

(Integer. 1) :- (U java.lang.Integer nil)
(.getClass 1) :- (U java.lang.Class nil)
(class 1) :- java.lang.Class

So the equivalent type of java.lang.Object (in Java-land) is
(U java.lang.Object nil) (in Clojure-land).

The exception to the implicit nil rule would be when a the result of an
interop
expression is a primitive value. A Java primitive cannot be null.

(. Integer MAXVALUE) :- int

Hopefully I expressed my thoughts clearly. Does this strategy seem
correct? Are there any other uses of null that I should be handling?

Thanks,
Ambrose

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to