[plt-scheme] contract question
(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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080206/f8a4847d/attachment.html>