[plt-scheme] macro question

From: Jos Koot (jos.koot at telefonica.net)
Date: Wed Jun 11 04:14:48 EDT 2008

Thanks, I admit that in the example the adition of the compact type 
information does in fact improve readability. And of course it is nice that 
it is checked.
You convinced me. Thanks.
Jos

----- Original Message ----- 
From: "Matthias Felleisen" <matthias at ccs.neu.edu>
To: "Jos Koot" <jos.koot at telefonica.net>
Cc: <plt-scheme at list.cs.brown.edu>
Sent: Tuesday, June 10, 2008 11:41 PM
Subject: Re: [plt-scheme] macro question


>
> On Jun 10, 2008, at 3:03 PM, Jos Koot wrote:
>
snip>
>
> Before we talk too abstractly here, let's look at an example:
>
> UNTYPED
>
>> #lang scheme
>>
>> ;; An A is one of:
>> ;; -- Number
>> ;; -- Boolean
>> ;; -- (cons A A)
>>
>> ;; A -> Number
>> ;; compute the sum of all numbers in the tree
>> (define (Sigma tree)
>>   (cond
>>     [(number? tree) tree]
>>     [(boolean? tree) 0]
>>     [else (+ (Sigma (car tree)) (Sigma (cdr tree)))]))
>>
>> (= (Sigma (cons (cons #t 5) 0)) 5)
>
> TYPED:
>
>> #lang typed-scheme
>>
>> (define-type-alias A (mu A (U Number Boolean (cons A A))))
>>
>> (: Sigma (A -> Number))
>> ;; compute the sum of all numbers in the tree
>> (define (Sigma tree)
>>   (cond
>>     [(number? tree) tree]
>>     [(boolean? tree) 0]
>>     [else (+ (Sigma (car tree)) (Sigma (cdr tree)))]))
>>
>> (= (Sigma (cons (cons #t 5) 0)) 5)
>>
>
>
> In general, Typed Scheme is as compact as untyped Scheme in HtDP  style. 
> And it is checked for you. -- Matthias
> 



Posted on the users mailing list.