Hi, there. Are you really filtering the list? I thought you were going to iterate the list and apply something/some actions to each element. If so, then List.iter is your option. Since floating point range is not a recommendation for the time being, you could first apply List.map to an integer list then List.iter like:

1
[100000 .. 999999] |> List.map (fun x -> float x) |> List.iter (fun x -> printfn "%f" x)

I think what you want is to transform the list, right?

Hope that helps!

By on 7/29/2008 7:49 PM ()

Hi Allen,

I am actually wanting to filter the list. I'm intrigued by the use of List.map to List.iter, doesn't it double the overhead by going through the list twice? Or, is F# clever enough to apply both functions on one pass?

Rich

By on 7/30/2008 12:49 AM ()

Hi Rich,

A couple of things:
- you shouldn't assume that F# will be smart enough to go through the list once, some things might get optimized but I believe this code will take two passes,
- doing an equality check on floats is not considered very safe
- it's also a bit weird to write List.filter (fun x -> float x = float x) as that doesn't accomplish anything; it just checks whether everyone in the list is equal to itself ...

Cheers, J

By on 7/30/2008 1:06 AM ()

Hi Jurgen,

1. I thought that would the case, which is why I didn't write it that way in the first place.

2. Is there some way I can check equality of two decimalised values that is safe?

3. The anonymous function provided was just an example. The actual function is below:

1
(fun x -> float x = sqSum (float x))

Thanks again for your help.

Rich

By on 7/30/2008 4:15 AM ()

Hi Rich & Jurgen

Fun fact for the day:

1
List.filter (fun x -> float x = float x)

does do something: if the input list contains, say, float or float32 values then it filters the list for NaN values, (NaN = NaN returns false under IEEE semantics)...

Disturbing but true :-)

don

By on 7/30/2008 4:51 PM ()

How about the following

1
let lst = List.filter (fun x -> float x = float x) [100000 .. 999999]
By on 7/29/2008 2:34 AM ()

I'm still finding my feet, I knew it'd be really simple. Thank you for your help.

Rich

By on 7/29/2008 2:48 AM ()
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