I know to most people this might be splitting hairs but lazy(seq) isnt really a lazy list. its a lazily evaluated list. This is different from a Lazy List because all elements of the list which is lazily evaluated will be computed the minute you force it. With a Lazy List only the elements used will be computed as they are consumed.

That means the code you listed above should use the LazyList class from Microsoft.FSharp.Compatibility.FSharp as follows

let nums_float = 2.0 |> LazyList.unfold( fun (i:float) -> Some(i,i+1.0))

Its a shame that LazyList is no longer in the core set of collections as it fills a use case that Seq doesnt. It caches its results as they are computed so if the list is ever traversed again it would not need to re compute the values. If it ever gets dropped then I will need to add its definition to my personal set of utility classes.

By on 8/17/2008 5:55 PM ()

Hi there

Did you take a look at Seq.cache?

thanks

don

By on 8/22/2008 9:32 PM ()

Thank you for your replies!

Seq.scan works for me ..

The idea for my program is from a Haskell program (Haskell School of Expression which

is really a great book) calculating the area of an ellipse with an infinite series and it can be expressed in f# with sequences as elegant as in Haskell with lists

If you are interested I can post my translation here (without any kind of warranty :) )

By the way, I am new to f# and using forums as well

Best regards

By on 8/23/2008 6:43 PM ()

There is Seq.scan. This will scan left as well.

By on 8/17/2008 3:45 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