views:

421

answers:

2

Is there an alternative/workaround for Seq.generate_using in Visual Studio 2010? The FSharp.PowerPack.dll is not available for 2010 AFAIK

+2  A: 

(Sorry about the PowerPack still not being available for 2010 yet.)

I don't recall if this already is true of the CTP update, but in internal bits I get the warning:

This construct is deprecated. This function will be removed in a future release. If necessary, take a copy of its implementation from the F# PowerPack and copy it into your application

so here is the code from the PowerPack:

#nowarn "9"

namespace Microsoft.FSharp.Compatibility

open System.Collections.Generic

module Seq = 
  let combine     ie1 ie2  = Seq.zip ie1 ie2
  let nonempty (ie : seq<'T>)  = use e = ie.GetEnumerator() in e.MoveNext() //'

  let generate openf compute closef = 
        seq { let r = openf() 
              try 
                let x = ref None
                while (x := compute r; (!x).IsSome) do
                    yield (!x).Value
              finally
                 closef r }

  let generate_using (openf : unit -> ('b :> System.IDisposable)) compute = //'
        generate openf compute (fun (s:'b) -> s.Dispose()) //'

  let cons (x:'T) (s: seq<'T>) = 
        seq { yield x
              yield! s }
Brian
thanks, Brian, works like a charm!
thinkhard
+2  A: 

FYI, the PowerPack binaries for .Net 4.0 Beta1 came online today:

http://www.microsoft.com/downloads/details.aspx?FamilyID=e475a670-9596-4958-bfa2-dc0ac29b4631&amp;displaylang=en

Brian