Re: [racket-users] hash-ref in typed Racket

2020-11-25 Thread Sam Tobin-Hochstadt
That particular pattern, with `(U String (-> String))`, will work, but your generalized version would be wrong if it worked. Consider: ``` (: unsound : (Immutable-HashTable Symbol (-> String)) -> String) (define (unsound h) ((hash-ref h (gensym) (lambda () "x" (unsound (hash)) ``` This pro

Re: [racket-users] hash-ref in typed Racket

2020-11-25 Thread Tim Jervis
For the record, this seems to work fine: #lang typed/racket (require/typed racket [hash-ref ((Immutable-HashTable Symbol (U (-> String) String)) Symbol (U String (-> String))

Re: [racket-users] hash-ref in typed Racket

2020-11-24 Thread Tim Jervis
Wouldn’t that possibility then have to be part of the type for the values in the hash? Maybe I don’t understand how types work for hashes. In this code: #lang typed/racket (define h : (Immutable-HashTable Integer (-> String)) (make-immutable-hash)) (hash-ref h 2 (thunk "H

Re: [racket-users] hash-ref in typed Racket

2020-11-24 Thread Sam Tobin-Hochstadt
Unfortunately, that doesn't work -- the values in the hash could include functions. Sam On Tue, Nov 24, 2020 at 7:25 AM Tim Jervis wrote: > > For the type of the third argument, rather than "any non-function", could > Typed Racket use the type of the values in the hash? > > On Tuesday, 21 April

Re: [racket-users] hash-ref in typed Racket

2020-11-24 Thread Tim Jervis
For the type of the third argument, rather than "any non-function", could Typed Racket use the type of the values in the hash? On Tuesday, 21 April 2020 at 15:51:00 UTC+1 Sam Tobin-Hochstadt wrote: > The problem here is with the optional third argument to `hash-ref`. > Typed Racket only allows `

Re: [racket-users] hash-ref in typed Racket

2020-04-21 Thread Hendrik Boom
On Tue, Apr 21, 2020 at 10:50:44AM -0400, Sam Tobin-Hochstadt wrote: > The problem here is with the optional third argument to `hash-ref`. > Typed Racket only allows `#f` or functions as the third argument. > Plain Racket allows any non-function value as a default, or a function > which is called t

Re: [racket-users] hash-ref in typed Racket

2020-04-21 Thread Sam Tobin-Hochstadt
The problem here is with the optional third argument to `hash-ref`. Typed Racket only allows `#f` or functions as the third argument. Plain Racket allows any non-function value as a default, or a function which is called to produce the default. Since "any non-function" is not expressible in Typed R