[racket] code review request for LRU code

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Tue Mar 12 23:46:19 EDT 2013

On 2013-03-12 13:16:02 -0700, Danny Yoo wrote:
> slab:lru dyoo$ racket untyped-client.rkt
> untyped-client.rkt:10:0: Type Checker: The type of lru-ref cannot be
> converted to a contract
>   in: (lru-ref l "greeting")
>   context...:
>    /Applications/Racket v5.3.2/collects/racket/private/modbeg.rkt:46:4
>    standard-module-name-resolver

I think this boils down to the fact that the following does not work:

  #lang racket

  (module b typed/racket
    (: f (All (A B) (A B -> (U A B))))
    (define (f x y) x)
    (provide f))

  (require 'b)
  f

The reason this doesn't work is because this contract does not work:

  #lang racket

  (define/contract (f x y)
    (parametric->/c (A B) (-> A B (or/c A B)))
    x)

  (f 1 "foo")

  ;;;

  f: broke its contract
   two of the clauses in the or/c might both match: B and A
   produced: #<A>
   in: the range of
       ...
        (parametric->/c (A B) ...)
   contract from: (function f)
   blaming: (function f)
   at: unsaved-editor160271:3.18

Cheers,
Asumu

Posted on the users mailing list.