[MLton] Re: [MLton-commit] r6352
Matthew Fluet
fluet at tti-c.org
Thu Jan 24 19:48:14 PST 2008
On Thu, 24 Jan 2008, Matthew Fluet wrote:
> On Thu, 24 Jan 2008, Vesa Karvonen wrote:
>> I've
>> been thinking about redefining all array types in my extended basis
>> library to include a generated hash value with the array.
>> Unfortunately, refs
>> can't be redefined in a library, so a language/basis library solution
>> would be better.
>
> The only aspects of refs that can't be redefined is the ref constructor for
> use in patterns. It is a fairly little used feature (and, arguably, a
> misfeature), so I suspect few clients would notice the difference.
Oops, I also forgot that the language disallows you to redefine the 'ref'
variable.
Nonetheless, I should point out that if one were to do:
structure MyRef :>
sig
eqtype 'a t
val mref : 'a -> 'a t
val ! : 'a t -> 'a
val := : 'a t * 'a -> unit
end =
struct
datatype 'a t = T of 'a ref * Word32.word
val w : Word32.word ref = ref 0wx0
fun mref v = T (ref v, !w) before w := !w + 0wx1
fun ! (T (r, _)) = General.! r
fun (T (r, _)) := v = General.:= (r, v)
end
then a structural hash (and also a structural equality) on an 'a MyRef.t
value would "do the right thing", because it would hash an integer along
with the constant hash of ref type. It is o.k. if the counter wraps,
because we're only using it for a hash. Equality will still check the
references.
More information about the MLton
mailing list