Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // our interface
- type IFoo = interface end
- // concrete type
- type Foo = inherit IFoo
- // interface with a generic argument
- type IBar<'foo when 'foo :> IFoo> = interface
- // we want to call BazUnion.Baz on an instance of IBar<Foo>, but there's no way to get the Foo out of the IBar
- // so we make that magic happen here.
- // in the concrete implementation of IBar, you'd keep a reference to an IFoo somewhere and then implement this
- // to dereference it
- abstract GetFoo : unit -> 'foo
- end
- // union with one type representing our interface
- type BazUnion = Baz of IFoo // should be B of #A, but how?
- // the generic version, if you like
- // flexible types are used to constrain generic type arguments to a particular base type
- //type GenericBaz<'foo when 'foo :> #IFoo> = Baz of 'foo
- module test =
- //val useSpecific: IBar<Foo> -> BazUnion (Baz of IFoo)
- let useSpecific(bar: IBar<Foo>) = Baz(bar.GetFoo())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement