[plt-dev] Call for Participation: Writing Typed Scheme wrapper modules

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Feb 25 10:22:41 EST 2009

Sam, it sounds like we should port test suites, too. -- Matthias



On Feb 25, 2009, at 10:11 AM, Jos Koot wrote:

> Sorry, on plt-dev now. Below is my first trial of math-wrapper with  
> some tests. Would this come close to what you expect? Comments are  
> appreciated.
>
> In the source text of scheme/math sinh and cosh are commented as  
> real sinh and real cosh, but as far as I can judge they work for  
> complex numbers too. The documentation of sinh and cosh does not  
> delimit the argument to be real. The wrapper allows complex arguments.
>
> If you are satisfied, I am in for another simple assignment.
>
> Jos
>
> PS Matthias, thanks for your answer to my question.
>
> ; Typed Scheme wrapper for scheme/math
>
> #lang typed-scheme
>
> (define-type-alias N->N (Number -> Number))
>
> (require/typed scheme/math
>  (pi Number)
>  (sqr N->N)
>  (sgn N->N)
>  (conjugate N->N)
>  (sinh N->N)
>  (cosh N->N))
>
> (define: (rsgn (r : Number)) : Number
>  (unless (real? r) (raise-type-error 'sgn "real" r))
>  (sgn r))
>
> (provide
>  pi
>  sqr
>  (rename-out (rsgn sgn))
>  conjugate
>  sinh
>  cosh)
>
> #|
> Should math not provide tanh?
> (define: (tanh (z : Number)) : Number (* -i (tan (* +i z))))
> (provide tanh)
> |#
>
> ; Some simple tests on math-wrapper
> #lang typed-scheme
> (require "math-wrapper.ss")
> (unless
>  (and
>   (= (sqr +i) -1)
>   (= (sqr -1) 1)
>   (= (sgn 0) 0)
>   (= (sgn -0.1) -1)
>   (< (magnitude (- (sinh -i) (* -i (sin 1)))) 1.e-10)
>   (< (magnitude (- (cosh -i) (cos 1))) 1.e-10)
>   (= (conjugate -i) +i)
>   (= pi 3.141592653589793)
>   (eq?
>    (call/cc
>     (lambda: ((cc : (Any -> Any)))
>      (define: (exit (x : Any)) : Any (cc 'ok))
>      (with-handlers ((void exit)) (sgn +i))))
>    'ok))
>  (error 'math-wrapper-test "check fails"))
>
>
>
> ----- Original Message -----
> From: "Sam TH" <samth at ccs.neu.edu>
> To: "Jos Koot" <jos.koot at telefonica.net>
> Sent: Wednesday, February 25, 2009 2:23 PM
> Subject: Re: [plt-dev] Re: [plt-scheme] Call for Participation:  
> Writing Typed Scheme wrapper modules
>
> Jos -
>
> Are you on the plt-dev list?  If so, I'd prefer to do discussion  
> there.
>
> Thanks,
> sam th
>
> On Wed, Feb 25, 2009 at 8:06 AM, Jos Koot <jos.koot at telefonica.net>  
> wrote:
> > In the typed-scheme reference I see base types Number and  
> Integer. I want a
> > type for reals, because many numerical functions accept/return  
> reals but not
> > complex numbers. Is this possible? How?
> > Jos
> > _________________________________________________
> > For list-related administrative tasks:
> > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
> >
>
>
>
> -- 
> sam th
> samth at ccs.neu.edu



Posted on the dev mailing list.