Or maybe this:

#lang typed/racket
(require racket/flonum)
(: S->F : String -> (Option Flonum))
(define (S->F s)
  (define n (string->number s))
  (and n
       (* (real-part n) 1.0)))

depending on what's wanted.


On Wed, Feb 13, 2013 at 9:18 PM, Robby Findler
<[email protected]>wrote:

> I feel like this is closer, but I'm not sure how to make those single
> precision floats into doubles (and then fix whatever else is wrong after
> that :)
>
> #lang typed/racket
> (require racket/flonum)
> (: S->F : String -> (Option Flonum))
> (define (S->F s)
>   (define n (string->number s))
>   (and n
>        (real? n)
>        (* n 1.0)))
>
>
>
> On Wed, Feb 13, 2013 at 9:15 PM, Matthias Felleisen 
> <[email protected]>wrote:
>
>>
>> That's just semantics, you dang logician
>>
>>
>> On Feb 13, 2013, at 10:09 PM, Carl Eastlund wrote:
>>
>> That might not be what he wants either, if he wants anything
>> representable as a flonum to be a flonum.  For instance, (S->F "5") is
>> #false by your implementation.  It's hard to tell exactly what S->F is
>> supposed to do without more of a specification.
>>
>> Carl Eastlund
>>
>>
>> On Wed, Feb 13, 2013 at 10:04 PM, Matthias Felleisen <
>> [email protected]> 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
>>>
>>> ____________________
>>>   Racket Users list:
>>>   http://lists.racket-lang.org/users
>>>
>>>
>>
>>
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>>
>>
>
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to