KevinRansom on dev16.10
Unrollover 16.9 (#10935) update target insertion branch Merge pull request #10940 from … and 1 more (compare)
KevinRansom on dev16.9
Update sdk version (#10944) * … (compare)
Hey folks,
I have a question about async workflows in .NET Core 2.0:
In one of my projects I had this line in the code:
async {
...
do! tran.CommitAsync()
}
Where CommitAsync()
returns a Task
. After upgrading to .NET Core 2.0, it gives a build error saying This expression was expected to have type 'Async<unit>'
, and I have to change it to this to make it compile:
async {
...
do! tran.CommitAsync() |> Async.AwaitIAsyncResult |> Async.Ignore
}
Do you know what's the reason for this? Was something changed in the compiler?
Task
to Async<unit>
(and from Task<T>
to Async<T>
), and when the FSharp.NET.Sdk package was removed from the project file, you no longer had those implicit casts available so you had to convert from Task
to Async<unit>
manually.
type IInterface<'T when 'T :> IInterface<'T>> =
abstract member Property : ICollection<IInterface<'T>>
type Implementor() =
interface IInterface<Implementor> with
member Property = List<Implementor>() :> ICollection<IInterface<Drop>>
Is there a reason why it is not possible to implement generic methods on a interface implementation?
type IMap =
abstract member Map: 'a -> 'b
type MapIntString() =
interface IMap with
member this.Map(x:int): string = sprintf "%i" x
type MapStringToInt() =
interface IMap with
member this.Map(x:string): int = 0
I know I can
type IMap<'a, 'b> =
abstract member Map: 'a -> 'b
type MapIntString() =
interface IMap<int, string> with
member this.Map x = sprintf "%i" x
type MapStringToInt() =
interface Map<string, int> with
member this.Map (x:string): int = 0
But that is not always possible or leads enormous amounts of code.
for example
type MapFoo(f: 'a -> 'b) =
interface Map with
member this.Map (x:Foo<'a>): Foo<'b> =
let (Foo a) = x
Foo (f a)
In the above example at the moment I would have to create a specialized impl for any combination of 'a
and 'b
of Foo<_>
whereas with an implementation like MapFoo
I just need the functions that do the conversion and give one of these functions during construction time
So my question is: are there any hard technical limitations (CLR/.NET) or type theory or type inferrence that prevents this? And if so why is it even possible to define the interface like
type IMap =
abstract member Map: 'a -> 'b
Why not have a compiler error when trying to define a generic abstract method that uses generic types that are not defined on the type itself?
.exe
anywhere,