Replies: 2 comments
-
I’m not in front of my computer, so not 100% sure, but it seems the compiler can’t resolve a common type, try constructing them with
|
Beta Was this translation helpful? Give feedback.
-
In front of my PC now, my suspicions were correct. These are your options: Tell C# the common join type, by providing the generic return argument to public static LoaderContainer<T> ToLoaderContainer<T>(this Option<T> o) =>
o.Match<LoaderContainer<T>>(val => new Loaded<T>(val), new NotLoaded<T>()); Tell C# the common join-type by casting one of the branches to the base type: public static LoaderContainer<T> ToLoaderContainer<T>(this Option<T> o) =>
o.Match(val => new Loaded<T>(val) as LoaderContainer<T>, new NotLoaded<T>()); Use the constructor functions, rather than public static LoaderContainer<T> ToLoaderContainer<T>(this Option<T> o) =>
o.Match(LoaderContainer.Loaded<T>, LoaderContainer.NotLoaded<T>); |
Beta Was this translation helpful? Give feedback.
-
I'm sure I'm doing something obviously stupid, but I can't see what.
I have the following code that generates a discriminated union...
I want to create an extension method that will convert an
Option<T>
toLoaded<T>
if theOption<T>
isSome
and toNotLoaded<T>
if theOption<T>
isNone
.Seems simple enough...
However, this gives a compiler error on the second parameter to
Match()
(namespaces removed to make it easier to read)...Cannot convert from 'NotLoaded' to 'Func<Loaded>'
I tried changing the second parameter to be a
Func<T>
......but this gave a compiler error on the whole second line...
Cannot implicitly convert type 'LanguageExt.Unit' to 'LoaderContainer'
What am I doing wrong? Thanks
Beta Was this translation helpful? Give feedback.
All reactions