I was implementing a C# interface in F# that looked something like:
public interface IThings
{
Stream ThingsInAStream()
}
My implementation looked something like:
type FSharpThings() =
interface IThings with
member this.ThingsInAStream() =
let ms = new MemoryStream()
// add things to stream
ms
Now I get the message:
The expression was expected to have type
Stream
but here has type
MemoryStream
I don't understand MemoryStream IS a Stream I know that I can cast it to as stream like:
ms :> Stream
Same goes for [|"string"|]
and IEnumerable<string>
it implements the interface and I can explicitly cast to it BUT it doesn't work automatically.
Why does this work?
let things:(IEnumerable<'a> -> 'a) = (fun f -> f.First())
let thing= things([|"";""|])
This is also automatic upcasting!