[racket] Typed racket and hash table

From: Manfred Lotz (manfred.lotz at arcor.de)
Date: Fri Jun 27 15:30:57 EDT 2014

I tried this:

#lang typed/racket/base

(: my-hash (HashTable Nonnegative-Integer (Listof String)))
(define my-hash (make-hash))



(: my-hash-add (-> Nonnegative-Integer String Void))
(define (my-hash-add size s)
  (let* ([val (hash-ref! my-hash size #f)])
    (if val
        (hash-set! my-hash size (cons s val))
        (hash-set! my-hash size (list s)))))

and got:

test.rkt:10:14: Type Checker: Polymorphic function `hash-ref!' could
not be applied to arguments: Argument 1:
  Expected: (HashTable a b)
  Given:    (HashTable Nonnegative-Integer (Listof String))
Argument 2:
  Expected: a
  Given:    Nonnegative-Integer
Argument 3:
  Expected: (-> b)
  Given:    False

  in: (hash-ref! my-hash size #f)
  context...:
   /home/manfred/racket/share/pkgs/typed-racket-lib/typed-racket/typecheck/tc-toplevel.rkt:249:0:
  type-check /home/manfred/racket/share/pkgs/typed-racket-lib/typed-racket/tc-setup.rkt:40:0:
  tc-setup /home/manfred/racket/share/pkgs/typed-racket-lib/typed-racket/typed-racket.rkt:25:4
   standard-module-name-resolver


What can I do to make this work?


-- 
Manfred






Posted on the users mailing list.