[plt-scheme] hash-has-key?

From: Thomas Chust (chust at web.de)
Date: Mon Mar 30 09:51:55 EDT 2009

2009-03-30 Sam TH <samth at ccs.neu.edu>:
> [...]
> What if the hash table had type Hash[String, Any]?

Then the return value of hash-ref would have type Option[Any], any
value found in the hash table would be returned by hash-ref wrapped as
a Some[Any] -- I don't see any problem there.

> [...]
> What if our language contains type inference?  What is the inferred
> type of (hash-ref h k)?

For any h of type Hash[K, V], hash-ref either extracts a value of type
V from h and returns it wrapped up as a Some[V] or it returns the
unique value of type None. The most specific common supertype of
Some[V] and None is Option[V] and this should be the type inferred for
hash-ref -- I don't see any problem here, either.

> [...]
> You should look at Richard Cobbe's dissertation [1], which contains a
> fuller discussion of these issues in the context of Java.

I downloaded it and put it on the stack of electronic publications to
look at. I only gave it a quick glance so far since a bunch of
articles from my own field of reseach have higher priority to be
read...

However, I think comparing the none value we are discussing here with
the null value of Java and many other languages doesn't make much
sense. The none value used in my examples is a value of a very
specific type while the null value of Java and others is usually a
value of (nearly) every type. Therefore the two values have very
different useful applications.

cu,
Thomas


-- 
When C++ is your hammer, every problem looks like your thumb.


Posted on the users mailing list.