[plt-scheme] make-mixin-contract

From: David Brooks (djb at untyped.com)
Date: Wed May 27 05:54:28 EDT 2009

Hi all,

I'm writing some mixins and wish to provide contracts for them. I have  
a scenario like:

(interface a<%> () aa)
(interface b<%> () bb)

(mixin (a<%>) (a<%> b<%>) ...)

so I want a contract that checks that:
[1] the input is class implementing a<%>;
[2] the output is a class implementing a<%> and b<%>;

I believe I can do this using implementation?/c in a function contract:

(-> (implementation?/c a<%>)
     (and/c (implementation?/c a<%>) (implementation?/c b<%>)))

However, then I found make-mixin-contract, and figured I should be  
using that instead:

http://docs.plt-scheme.org/reference/Object_and_Class_Contracts.html#(def._((lib._scheme/ 
class..ss)._make-mixin-contract))

> (make-mixin-contract type ...) → contract?
>    type : (or/c class? interface?)
> Produces a function contract that guarantees the input to the  
> function is a class that implements/subclasses each type, and that  
> the result of the function is a subclass of the input.
>

My problem is that make-mixin-contract only seems to deal with the  
input types. How should I specify the extra output types? Am I just  
misunderstanding the purpose of make-mixin-contract?

Cheers,
D
--
David Brooks
http://www.untyped.com








Posted on the users mailing list.