Monday, 15 September 2014

Nested Interfaces in C# -



Nested Interfaces in C# -

i trying implement ifunctor interface [haskell's fuctor class] , maybe interface create 2 classes: just , nothing.

so far have:

public interface ifunctor<a> { ifunctor<b> fmap<b> (func<a,b> f); } public interface maybe<a> : ifunctor<a> { maybe<b> fmap<b> (func<a,b> f); } public class nothing<a> : maybe<a> { public maybe<b> fmap<b>( func<a,b> f ){ homecoming new nothing<b>(); } }

however get

`pr.nothing<a>' not implement interface fellow member `ifunctor<a>.fmap<b> (system.func<a,b>)' , best implementing candidate `pr.nothing<a>.fmap<b> (system.func<a,b>)' homecoming type `pr.maybe<b>' not match interface fellow member homecoming type `ifunctor<b>'

isn't maybe<b> fellow member of ifunctor<b>?

solution

i ended writing

public interface ifunctor<a> { ifunctor<b> fmap<b> (func<a,b> f); } public interface maybe<a> : ifunctor<a> { //some stuff not fmap } public class nothing<a> : maybe<a> { public ifunctor<b> fmap<b>( func<a,b> f ){ homecoming new nothing<b>(); } }

maybe<a>.fmap() not override ifunctor<a>.fmap(). type implements maybe<a> need need implement both maybe<a> , ifunctor<a>.

public interface ifunctor<a> { ifunctor<b> fmap<b>(func<a, b> f); } public interface maybe<a> : ifunctor<a> { maybe<b> fmap<b>(func<a, b> f); } public class nothing<a> : maybe<a> { public maybe<b> fmap<b>(func<a, b> f) { homecoming new nothing<b>(); } //this explicit implementation of ifunctor<a>.fmap<b> //which in turn invokes method above. ifunctor<b> ifunctor<a>.fmap<b>(func<a, b> f) { homecoming this.fmap(f); } }

c# interface

No comments:

Post a Comment