typed-racket/typed-racket-test/succeed/pr390-variation-5.rkt
Ben Greenman fae58e140d add types for Immutable-HashTable, Mutable-HashTable, Weak-HashTable (#559)
The old 'HashTable' type is now the union of the other 3 hash types.

- all operations that used to work on 'HashTable's still work,
  but some now have more specific outputs
- `#hash` literals have type `ImmutableHash`
- `immutable?` and `hash-weak?` are filters
- `Mutable-` and `Weak-` hashes have corresponding `Top` types, `HashTableTop` is now a union
- the contact for `(U (Immutable-Hash K1 V1) (Mutable-Hash K2 V2))` is ONE `hash/c`

Minor notes:

- renamed internal identifiers containing 'Hashtable' to all use 'HashTable'
- add Racket guide/reference 'secref' functions
2017-06-26 18:00:19 -04:00

27 lines
754 B
Racket

#lang racket/base
;; Test contract generation
;; - HashTable should make 1 contract, not an or/c
;; - (U #f HashTable) should make an or/c with 2 things
;; (This file only generates contracts, it doesn't check that they are not redundant.)
(module u racket/base
(define u-hash (make-immutable-hash '((a . 1) (b . 2))))
(provide u-hash))
(module t typed/racket
(require/typed (submod ".." u)
(u-hash (U Integer #f (Immutable-HashTable Symbol Integer) (Mutable-HashTable String String))))
(define t-hash : (HashTable Symbol Integer)
(make-immutable-hash '((a . 1) (b . 2))))
(provide u-hash t-hash))
(require 't racket/contract)
(void
(hash-ref u-hash 'a)
(hash-set u-hash 'c 3)
(hash-ref t-hash 'a)
(hash-set t-hash 'c 3))