<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>What I did to get around this was use require/typed with a more useful type, but when I tried it again just now it didn’t work any more. This used to work, what changed? And why would it expect a flat contract anywhere? </div><div><br></div><div><div><font face="Courier New">#lang typed/racket</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(require/typed racket/base</font></div><div><font face="Courier New"> [hash (All (a b)</font></div><div><font face="Courier New"> (case-> [-> (HashTable a b)]</font></div><div><font face="Courier New"> [a b -> (HashTable a b)]</font></div><div><font face="Courier New"> [a b a b -> (HashTable a b)]</font></div><div><font face="Courier New"> [a b a b a b -> (HashTable a b)]</font></div><div><font face="Courier New"> [a b a b a b a b -> (HashTable a b)]</font></div><div><font face="Courier New"> [a b a b a b a b a b -> (HashTable a b)]</font></div><div><font face="Courier New"> [a b a b a b a b a b a b -> (HashTable a b)]</font></div><div><font face="Courier New"> [a b a b a b a b a b a b a b -> (HashTable a b)]</font></div><div><font face="Courier New"> [a b a b a b a b a b a b a b a b -> (HashTable a b)]</font></div><div><font face="Courier New"> ))])</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(hash 1 2)</font></div></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">. Type Checker: Type (All (a b) (case-> (-> (HashTable a b)) (-> a b (HashTable a b)) ....)) could not be converted to a contract: required a flat </font><span style="font-family: 'Courier New';">contract but generated an impersonator contract in: (All (a b) (case-> (-> (HashTable a b)) (-> a b (HashTable a b)) ....))</span></div><br><div><div>On Oct 30, 2014, at 7:53 AM, Konrad Hinsen <<a href="mailto:konrad.hinsen@fastmail.net">konrad.hinsen@fastmail.net</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Sam Tobin-Hochstadt writes:<br><br><blockquote type="cite">This isn't a different version of `hash` -- instead, it's the same<br>version, with a type that doesn't accept every working untyped Racket<br>program.<br></blockquote><br>This make sense from the point of view of the language implementation,<br>but not from the point of view of the language user.<br><br>For me as a programmer, Typed Racket is a different language from<br>Racket, because a valid program in one language is not a valid program<br>in the other. Whether or not Typed Racket's hash ends up calling <br>plain Racket's hash is an implementation detail I don't care about,<br>except perhaps when dealing with interfacing modules in the two<br>languages.<br><br>From this point of view, Typed Racket is to a large degree an<br>undocumented language. Much of the documentation simply points to the<br>one of plain Racket, which doesn't fully apply. Moreover, there is no<br>simple set of rules that would let me deduce Typed Racket's API (which<br>includes types) from plain Racket's API.<br><br><blockquote type="cite">The type of `hash` is one that comes up a bunch, and we should<br>probably just add a few special cases that handle 2/4/6 arguments.<br>Unfortunately, we don't yet have a mechanism for fully supporting the<br>behavior of `hash`, and so there will be cases that work in untyped<br>Racket but not in Typed Racket.<br></blockquote><br>I wouldn't expect the type checker to support all working plain Racket<br>code. But I do expect Typed Racket to provide equivalent (though<br>possibly syntactically different) APIs for common tasks such as<br>creating an immutable hash table from key-value pairs.<br><br>I suppose the problem with hash is the indefinite number of arguments.<br>One way out is a list of key-value pairs, with hash becoming the inverse<br>of hash->list. It's certainly much easier to port untyped code to such a<br>somewhat different syntax than to have no straightforward option at all.<br><br>This is BTW what I used as a workaround:<br><br> (: list->hash (All (a b) (-> (Listof (Pairof a b)) (HashTable a b))))<br> (define (list->hash lst)<br> (for/fold ([hsh : (HashTable a b) (hash)])<br> ([kv : (Pairof a b) lst])<br> (hash-set hsh (car kv) (cdr kv))))<br><br>Konrad.<br>____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>