Inherit from Seq

I want to create my own custom collection type.

I define my collection as:

type A(collection : seq<string>) = member this.Collection with get() = collection interface seq<string> with member this.GetEnumerator() = this.Collection.GetEnumerator() 

But this will not compile No implementation was given for 'Collections.IEnumerable.GetEnumerator()

How can I do it?

+6
source share
1 answer

F # seq is actually just an alias for System.Collections.Generic.IEnumerable<T> . Generic IEnumerable<T> also implements non-generic IEnumerable , and so your F # type should also do this.

The easiest way is to just have a non-generic call in common

 type A(collection : seq<string>) = member this.Collection with get() = collection interface System.Collections.Generic.IEnumerable<string> with member this.GetEnumerator() = this.Collection.GetEnumerator() interface System.Collections.IEnumerable with member this.GetEnumerator() = upcast this.Collection.GetEnumerator() 
+12
source

Source: https://habr.com/ru/post/912888/


All Articles