[racket] TR Numeric Tower

From: Ray Racine (ray.racine at gmail.com)
Date: Wed Feb 13 22:33:02 EST 2013

Well long day... I was getting lost in basically getting a Number -> Float.

So for example:

(: S->F : String -> (Option Float))
(define (S->F s)
  (define n (string->number s))
  (and (flonum? n) n))

(S->F "3") ;; Fails


For some reason I was thinking I had to got through exact? and inexact?
type tests and I didn't find the real->double-flonum until just now.

The below works for me.

(: S->F : String -> (Option Float))
(define (S->F s)
  (let ((n (string->number s)))
    (if (real? n)
        (real->double-flonum n)
        #f)))







On Wed, Feb 13, 2013 at 10:04 PM, Matthias Felleisen
<matthias at ccs.neu.edu>wrote:

>
> #lang typed/racket
>
> (: S->F : String -> (Option Float))
> (define (S->F s)
>   (define n (string->number s))
>   (and (flonum? n) n))
>
> I assume you mean to convert strings into floats, if possible.
>
> But you may like the funny answers better -- Matthias
>
>
>
> On Feb 13, 2013, at 9:49 PM, Ray Racine wrote:
>
> > What is the most efficient way to write the following method in TR?
> >
> > (: S->F (String -> (Option Float)))
> >
> >
> > ____________________
> >  Racket Users list:
> >  http://lists.racket-lang.org/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130213/5ed73f06/attachment.html>

Posted on the users mailing list.