Version française
Home     About     Download     Resources     Contact us    
Browse thread
Arg-module: Float-Args also accept integer values
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Arg-module: Float-Args also accept integer values
On Tue, Aug 08, 2006 at 02:40:58PM -0700, Sachin Shah wrote:
> On 8/8/06, Oliver Bandel <oliver@first.in-berlin.de> wrote:
> >On Tue, Aug 08, 2006 at 03:19:15PM -0600, William D. Neumann wrote:
> >> On Tue, 8 Aug 2006, Oliver Bandel wrote:
> >>
> >> >Is this a wanted behaviour?
> >> >It's an implicit conversion from the integer value in the cli-string
> >> >to float. Even if this is very convenient for a user, it is not
> >> >completely following OCaml's philosophy (regarding types).
> >>
> >> Not really.  It's the same behavior as float_of_string (because it uses
> >> float of string).
> >>
> >> # float_of_string "42";;
> >> - : float = 42.
> >>
> >[...]
> >
> >Ah, ok, I see.
> >
> >Thanks!
> >
> >(But.... shouldn't throw this an eception, because it's
> > an int, not a float?!)
> >
> >Ciao,
> >   Oliver
> 
> No, because 42 is a valid int and a valid float.  Since integers are a
> proper subset of floating-point numbers, this is the correct behavior
> for float_of_string.
> 
[...]

===========================================
first:~ oliver$ ocaml
        Objective Caml version 3.09.2

# let floatingpoint_id (x:float) = x;;
val floatingpoint_id : float -> float = <fun>
# floatingpoint_id 42;;
This expression has type int but is here used with type float
# 
===========================================

Ciao,
   Oliver