2

I'm creating a module that will be used by C# code, so I would rather not return the LazyList<> directly. If I did, the C# would have to reference the FSharp.PowerPack, which seems strange.

So I would rather return a IList<>, but when I try to do something like:

let x = LazyList.ofSeq {0..10}
let y = x :> IList<int32>

However, this gives me the error:

The type 'LazyList<int> is not compatible with the type 'IList<int>'

This leads me to believe that LazyList<> does NOT implement IList<>. Is this true?

What am I missing?

Mark Pattison
  • 2,964
  • 1
  • 22
  • 42
poy
  • 10,063
  • 9
  • 49
  • 74
  • This [post](http://stackoverflow.com/q/9201402/2145211) could be helpful – Harrison Oct 28 '13 at 15:30
  • 5
    `IList<_>` exposes things like `Count` which only make sense if the list is fully constructed, so it makes sense that `LazyList<_>` doesn't implement that interface. – kvb Oct 28 '13 at 15:41
  • @kvb: I was taking DoctorJones (http://stackoverflow.com/questions/2689986/lazylistt-vs-system-lazylistt-in-asp-net-mvc-2/2690307#2690307) at his word a bit... But it definately makes sense that it wouldn't be able to do most of the functionality from `IList<>` – poy Oct 28 '13 at 15:46
  • I think that's actually in reference to a different `LazyList<_>` class, not F#'s. – kvb Oct 28 '13 at 16:04
  • 2
    There is `LazyList` in the ExtCore library, which also does *not* implement `IList` (https://github.com/jack-pappas/ExtCore/blob/master/ExtCore/Collections.LazyList.fs), but I think it would be a reasonable addition, so perhaps you could submit a pull request and use that? – Tomas Petricek Oct 28 '13 at 16:30

1 Answers1

4

It is true, LazyList does not implement the IList interface. It implements IEnumerable though.

[<Sealed>]
type LazyList<'T> =
   interface IEnumerable<'T>
   interface System.Collections.IEnumerable
treze
  • 3,159
  • 20
  • 21