f# - Union type with interface in signature file -


given following code int implementation file:

namespace lib  module test =      type itest =         abstract member istest: bool      type t = test          interface itest             member this.istest = true      let create () = test  

and following signature file:

namespace lib module test =        [<interface>]     type itest =         abstract member istest: bool      type t       val create: unit -> t 

the following warning occurs:

warning 2. type implements interface 'test.itest' not revealed signature. should list interface in signature, interface discoverable via dynamic type casts and/or reflection.

how should signature of type t changed in signature file conform implementation?

you should list interfaces in type definition inside module signature (fsi) file, example:

namespace lib module test =        [<interface>]     type itest =         abstract member istest: bool      type t =         interface itest         //you can list other interfaces here      val create: unit -> t 

note, there no member listing when specify interfaces in fsi files (we omitted istest member when defining type t), member listing should part of module implementation (fs) file.

update

the above example valid f# 4.0. since op tagged question f#-3.0 tag, syntax older f# should little different -- in fsi file instead of

type t = ... 

use

type t ... 

this has changed in original example if plan on upgrading f# 4+. compiler display relevant warnings change


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -