Thank you, Brian, that was very helpful.

On 05/23/2016 03:46 PM, Brian LaChance wrote:
> Hi, Matthew
> 
> I'm pretty sure the problem you're having is that, even when you make
> a hash table using hash, TR can't tell that it's immutable. It only
> has one hash table type, HashTable, which is used for both mutable and
> immutable variants. You'll see a similar problem with your cons
> examples if you switch those to mutable pairs using mcons/MPairof.
> 
> As for why you can annotate the first hash expression, the one that
> works as expected, it's the same reason you can define t* with an
> annotation like
> 
> (: t* (HashTable Any Any))
> (define t* (hash 'a 1 'b "cat"))
> 
> The other examples don't work because when you define t* without the
> explicit annotation, it's as if you had annotated it with the "given"
> type that you see in the error messages. If you were able to then
> later annotate it with the rejected types, you could put arbitrary
> values into the hash table. A consumer who thought they were getting
> (U String One) values out (after all, that's t*'s type) could be
> surprised with a non-One Integer.
> 
> Commingling mutable and immutable hash tables into the same type is
> definitely confusing in TR. Hopefully we can tease them apart in the
> future to remove at least some of the confusion. Let me know if this
> didn't help clear things up.
> 
> -Brian
> 
> On Mon, May 23, 2016 at 6:54 AM, Matthew Eric Bassett
> <mebass...@gegn.net> wrote:
>> Hi all,
>>
>> I noticed something weird today when playing around with typed racket (and
>> flirting with the idea of using it in production).
>>
>> If I do something like:
>>
>> -> (ann (cons 'a 1) (Pairof Any Any))
>> - : (Pairof Any Any)
>> '(a . 1)
>>
>> That works as expected.  As does:
>>
>> -> (define t (cons 'a 1))
>> -> (ann t (Pairof Any Any))
>> - : (Pairof Any Any)
>> '(a . 1)
>>
>> Now, if I do
>>
>> -> (ann (hash 'a 1 'b "cat") (HashTable Any Any))
>> - : (HashTable Any Any)
>> '#hash((a . 1) (b . "cat"))
>>
>> That also works as expected.  Things get weird if I do:
>>
>> -> (define t* (hash 'a 1 'b "cat"))
>> -> (ann t* (HashTable Any Any))
>>
>> This gives a type mismatch error:
>>
>> ; readline-input:30:5: Type Checker: type mismatch
>> ;   expected: (HashTable Any Any)
>> ;   given: (HashTable Symbol (U String One))
>> ;   in: t*
>>
>>
>> Am I being completely daft here?  Is there some hidden knowledge
>> required to use
>> hash tables here?
>>
>> Note that the following also does not work:
>>
>> -> (ann t* (HashTable Symbol (U String Integer)))
>> ; readline-input:31:5: Type Checker: type mismatch
>> ;   expected: (HashTable Symbol (U Integer String))
>> ;   given: (HashTable Symbol (U String One))
>> ;   in: t*
>>
>> Regards,
>>
>> Matthew Eric
>>
>> --
>> Matthew Eric Bassett | http://mebassett.info
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
> 

-- 
Matthew Eric Bassett | http://mebassett.info

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to