[racket] Is this a good design

From: David Van Horn (dvanhorn at ccs.neu.edu)
Date: Wed Feb 29 15:41:15 EST 2012

On 2/29/12 3:22 PM, Raoul Duke wrote:
>> but *write it down*.  How are we to know, as reader's of your contract and
>> purpose statements, that we have to provide non-empty strings?
> er, can you make a new EmptyString type and use that in the contract
> part of the comment?

What's a type?

You can define a class (i.e. a set) of values with a data definition. 
The more useful thing here is a data definition for a non-empty string, 
not an empty string.

    ;; A NonEmptyString is a String that is not "".

Now you can write the contract as:

    ;; NonEmptyString -> String

or, to be really precise:

    ;; NonEmptyString -> NonEmptyString

or, to be really really precise:

    ;; NonEmptyString -> 1String


    ;; A 1String is a String such that string-length is 1.

But I actually think Roelof's contract and (revised) purpose statements 
were just fine.


Posted on the users mailing list.