[racket-dev] A Const type constructor

From: D Herring (dherring at tentpost.com)
Date: Wed Jul 25 22:10:22 EDT 2012

On 07/25/2012 12:29 PM, Neil Toronto wrote:

> What if TR had a notion of const-ness, like in C? Suppose (Vectorof A)
> is a subtype of (Const-Vectorof B) when A is a subtype of B, and
> (Const-Vectorof A) is never a subtype of (Vectorof B).

In C, "const" is a contract on the function type, not on the parameter 
data type.  This can be a very useful contract.  Once const applies to 
a variable, it becomes sticky and requires an explicit (and easily 
searched) const_cast downgrade to become mutable again.

This can be useful and quite annoying.  Using const in one spot often 
causes a snowball effect where it must be manually propagated to other 
function prototypes.  C++ allows certain fields to be marked as 
mutable, even when the containing object is const.  A more dynamic 
language might be able to decorate the value instead of the function, 
or at least infer const-ness where possible?

- Daniel

Posted on the dev mailing list.