There's a second pattern, similar to Keno's, that can also often help avoid
needing invoke:
function f(::Abstract)
check_invariants(x)
# does work on x
end
check_invariants(::Abstract) = nothing
check_invariants(x::Subtype) = (x.y == 4 && error("f(x) is undefined for
x.y=4"))
On Thu, Jul 17, 2014 at 2:59 AM, Stefan Karpinski <[email protected]>
wrote:
> I've occasionally found cases where invoke seems to be the only
> non-annoying way to accomplish some dispatch, but it's remarkably rare.
> Still, it does seem to happen.
>
>
> On Wed, Jul 16, 2014 at 11:55 PM, Markus Roberts <[email protected]>
> wrote:
>
>>
>> Thank you both...invoke(bar,(Fu,),f) has exactly the semantics I was
>> looking for (esp. being able to specify which type constraint I'm
>> loosening in the case where there are multiple args participating in the
>> dispatch.
>>
>> As for Keno's suggestion that I refactor into a primary/secondary method
>> pattern, I can see how that would be the right solution in some cases, but
>> doesn't feel like a good fit in my present case; my subtype's "around"
>> method is only there to maintain additional invariants imposed by the
>> subtype, and having an additional function that does the "actual work"
>> without maintaining the invariant feels...icky.
>>
>> Thanks again for the prompt replies,
>> -- MarkusQ
>>
>>
>