[plt-scheme] contract question
We're still figuring out how or/c should work in the general
higher-order case. For now, it only accepts a single non-flat
contract. That is, you can write:
(or/c false/c (-> integer? integer?))
using or/c.
In v4, the arrow contract notation has been cleaned up, so looks a
little bit different, and so the new documentation uses it instead,
but you might find this useful:
http://pre.plt-scheme.org/docs/html/guide/contracts.html
Robby
On Feb 6, 2008 7:26 AM, Jos Koot <jos.koot at telefonica.net> wrote:
>
>
> (case (-> ..) (-> ..)) works perfect. Why did I miss that? It is in the
> docs, although at the very end of the chapter.
>
> I did already go along the line of your example with ->*, but it is less
> restrictive than I want.
>
> Thanks,
> Jos
>
>
> ----- Original Message -----
> From: Dave Gurnell
> To: plt-scheme at list.cs.brown.edu
> Sent: Wednesday, February 06, 2008 2:04 PM
> Subject: Re: [plt-scheme] contract question
>
> I'm not sure why you can't use or/c (see below), but you should be able to
> use ->* or case->:
>
>
>
>
> (define (example a (b #f))
> (if b (+ a b) (void)))
>
> ->* specifies contracts for variable arity procedures:
>
>
>
> (provide/contract
> (example (->* (number?) (number?) (or/c number? void?))))
>
> case-> is intended for contracts on case-lambdas, but it should work okay
> here:
>
>
>
> (provide/contract
> (example (case-> (-> number? number? number?)
> (-> number? void?))))
>
>
> I thought or/c could only be used on value contracts but the documentation
> suggests otherwise.
>
>
>
>
>
>
>
> Cheers,
>
>
> -- Dave
>
>
>
>
> Finally I decided to try contracts. I tried:
>
> #| require one or two numbers
> promise to return a number if two numbers are given
> promise void if one number is given |#
>
> #lang scheme
>
> (provide/contract
> (example
> (or/c
> (-> number? number? number?)
> (-> number? void?))))
>
> (define (example a (b #f))
> (if b (+ a b) (void)))
>
> This compiles, but it wont run:
>
> Welcome to DrScheme, version 3.99.0.10-svn4feb2008 [3m].
> Language: Module custom.
> or/c: two arguments, (-> number? void?) and (-> number? number? number?),
> might both match #<procedure:example>
>
> Why? What is wrong in my contract? May be I am wanting an impossible
> contract?
> or/c repeats exactly what I want, but does not accept it.
> I think I am missing something fundamental, but I can't find an answer in
> the docs.
> Thanks, Jos Koot_________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
>
> ________________________________
>
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>