type IRunnable =
abstract member Run: unit -> unit
type IPrintable =
abstract member Print: unit -> unit
type Service() =
class
interface IRunnable with
member _.Run() =
backgroundTask { printfn "run" } |> ignore
interface IPrintable with
member _.Print() = printfn "print"
end
let env =
{ new IPrintable with
member _.Print() = printfn "print"
interface IRunnable with
member _.Run() =
backgroundTask { printfn "run" } |> ignore }
let print (x: IPrintable) = x.Print()
let run (x: IRunnable) = x.Run()
let doIt (env: #IPrintable & #IRunnable) =
print env
run env
doIt env // <- error:
(*
The type 'IPrintable' is not compatible with the type 'IRunnable'. Why?
*)
let env = Service()
doIt env
I do not understand why got error.
I think env and Service type re equal.
It is works, but it lost meaning
to use expressions
type IPR =
inherit IPrintable
inherit IRunnable
let env =
{ new IPR with
member _.Print() = printfn "print"
member _.Run() =
backgroundTask { printfn "run" } |> ignore }