With the int32, float, and int64 functions respectively. Here's an fsi session using them:

1
2
3
4
5
6
> int32 1.0;;
val it : int32 = 1
> float 1;;
val it : float = 1.0
> int64 1.0;;
val it : int64 = 1L
By on 8/31/2008 12:25 PM ()

Thanks for answering my question. However when I type those respective functions into fsi without parameters and press enter their signatures say they take int not float or some generic type. However when I use them they work fine. Does anyone have any documentation on how these functions work?

By on 8/31/2008 2:12 PM ()

I may be wrong and I hope that some one will correct me if I am, but I think these functions are making use of the System.IConvertible interface which allows you to convert pretty much all of the system types into each other. So although the signatures do not list them, you can pass, for example, a byte in:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
> let x = new System.Byte();;
val x : System.Byte

> x;;
val it : System.Byte = 0uy

> int x;;
val it : int = 0

> float x;;
val it : float = 0.0

> int64 x;;
val it : int64 = 0L
By on 8/31/2008 7:44 PM ()

These functions have been around in F# for about 12 months now, and are statically resolved in much the same way as "+" and the other arithmetic operators.

In the Intellisense in VisualStudio the basic type signature for "int64" looks like this:

val int64 : 'a -> int64 (requires member Int64)

In more detail it looks like this:

val int64 : 'a -> int64 when 'a : (static member ToInt64 : 'a -> int64) and default 'a : int

Both are indicating that the static type of the argument must support a ToInt64 method. As far as F# is concerned all the primitive .NET types are assumed to support this method (see the F# specification on constraints and constraint solving for more details)

The operations are statically resolved, inlined and compile to highly efficient code (one .NET IL instruction)

Thanks

don

By on 8/31/2008 9:12 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper