Open gusty opened 1 year ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public interface ISemigroup<T>
{
static abstract T Plus(T x, T y);
}
public interface INonEmptySeq<T> : IEnumerable<T>
{
T First { get; }
}
public interface ISemigroupNonEmptySeq<T> : INonEmptySeq<T>
// ISemigroup<ISemigroupNonEmptySeq<T>>
{
}
public record NonEmptySeq<T1>(
Func<IEnumerator<T1>> getEnumerator,
Func<IEnumerator> getNonGenericEnumerator,
Func<T1> getFirst) : ISemigroupNonEmptySeq<T1>,ISemigroup<INonEmptySeq<T1>>
{
public IEnumerator<T1> GetEnumerator() => getEnumerator();
IEnumerator IEnumerable.GetEnumerator() => getNonGenericEnumerator();
public T1 First => getFirst();
public static INonEmptySeq<T1> Plus(INonEmptySeq<T1> x, INonEmptySeq<T1> y)
{
INonEmptySeq<T1> unsafeOfSeq(IEnumerable<T1> seq)
{
return new NonEmptySeq<T1>(
seq.GetEnumerator,
seq.GetEnumerator,
() => seq.First()
);
}
return unsafeOfSeq(x.Concat(y));
}
}
Is the same allowed for non-statics?
No, interfaces can't have non-static members, only statics. I think in C# they can have default implementations for instance members, but that's a different story.
Static abstract implemented/inherited in another interface doesn't work
Repro steps
Expected behavior
Compile
Actual behavior
Then I try what the error message suggests:
Expected behavior
Compile
Actual behavior
Known workarounds
Use C#
Related information
Microsoft (R) F# Interactive version 12.8.0.0 for F# 8.0