[racket] Making a contract between a function and "the world in general"

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Fri Oct 7 12:27:22 EDT 2011

It would be good if we had a provide form that meant "provide it with
the contract it already has" that you could use as a short-hand to
avoid duplicating the contract (really: avoid giving the contracts
names and managing those names since contracts are values).

We have talked about that before, but I believe that Matthias didn't
like the idea for some reason, but I'm foggy on the details.

Robby

On Fri, Oct 7, 2011 at 11:02 AM, Neil Toronto <neil.toronto at gmail.com> wrote:
> Using define/contract or a contract region, we can make a function with a
> contract between the function and the module. If the function is provided
> and a requiring module applies bad arguments, the module gets blamed.
>
> Or we can use (provide (contract-out ...)) instead, and make a contract
> between the module and whatever requires the module. If a requiring module
> applies bad arguments, the requiring module gets blamed.
>
> I'd like to make a function with a contract between the function and the
> world in general, where if anything applies bad arguments - whether in the
> defining module or out of it - it gets blamed. Is there a way to do that
> besides using both define/contract and contract-out, and duplicating the
> contract?
>
> Is there a way to "lift" contracts to the module level?
>
> I think of it in analogy to this:
>
>
> #lang racket/load
>
> (module provider0 racket
> (define (takes-a-list xs) (void))
> (provide/contract (takes-a-list ((listof real?) . -> . void?))))
>
> (module provider1 racket
> (require 'provider0)
> (provide (all-from-out 'provider0)))
>
> (require 'provider1)
> (takes-a-list (λ (x) x))
>
>
> Here, provider1 isn't blamed for the bad argument, even though it provided
> it.
>
> Neil T
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users



Posted on the users mailing list.