Le vendredi 20 mai 2016 à 05:53 -0700, Christoph Ortner a écrit :
> I want to understand how to share methods across modules who don't
> know of one another.  I understand that this is discussed in various
> places; I tried to go through may issues, but in the end I didn't get
> a good picture of what I should do now. Long post - my question in
> the end is: is creating an interface module the only (best) way to
> achieve this right now, or are there better / more elegant / ...
> constructs?
Yes, I think that's the recommended solution, and I don't know of plans
to change this. It can be a bit annoying, but it has the advantage of
forcing collaboration to define common interfaces across
modules/packages. You should be able to find threads about this in the
archives where the arguments against automatically merging methods from
different modules are developed.


Regards

> Consider this situation:
> 
> module A
>     export TA, blib
>     type TA end
>     blib(::TA) = "A"
> end
> 
> module B
>     export blib, dosomething
>     blib(::Any) = "any"
>     dosomething(x) = blib(x)
> end
> 
> using A, B
> dosomething(TA())
> 
> #  "any"
> 
> I want the output to be "A", but it will be "any", because module B
> doesn't know about A.blib. The standard solution is this (?yes?):
> 
> module B
>     export blib, dosomething
>     blib(::Any) = "any"
>     dosomething(x) = blib(x)
> end
>     
> module A
>     import B
>     export TA
>     type TA end
>     B.blib(::TA) = "A"
> end
> 
> using A, B
> dosomething(TA())
> 
> #  "A"
> 
> However, this requires A to know about B (or vice-versa). Suppose now
> that I want to be able to use functionality across modules that don't
> know of one another, so this sort of import is not an option. The
> *only* solution I see at the moment is to define a "super-module"
> that specifies the interface
> 
> module Super
>    export blib
>    blib() = error("this is just an interface")
> end
> 
> module A
>     import Super
>     export TA
>     type TA end
>     Super.blib(::TA) = "A"
> end
> 
> module B
>     using Super
>     export TB, dosomething
>     Super.blib(::Any) = "any"
>     dosomething(x) = blib(x)
> end
> 
> using B, A
> dosomething(TA())
> 
> To repeat my question: is this the recommended way to achieve that A
> and B should not have to know of each other?
> 
> Long-term: how is this going to evolve, which are the most relevant
> issues to follow?
> 
> Any comments would be appreciated. 
> 
> Christoph
> 

Reply via email to