In dynamic languages, values rather than expressions have types. As a
result the evaluation context of a function call doesn't have a type, so
you can't overload functions on return type. In this case, I'd be inclined
to go with different functions. You have to ask yourself what `-` means –
it should have a single coherent meaning across all its methods. Given a
single meaning for `-` either

   1. `-` doesn't make sense when applied to dates, or
   2. only one of these definitions makes sense for `-` applied to dates.

I suspect that the right meaning of subtracting two dates is to give the
number of calendar days.


On Sun, Apr 20, 2014 at 4:31 AM, MikeEI <[email protected]> wrote:

> I hope not too contrived, just for learning the Julia style:
> Let's say one wants to implement different day count methods that have
> same argument types (enddate, begindate), using (-), means not using
> different function names. Which way would You recommend to realize
> something like this:
> (-) (enddate, begindate) =  (alg for # of calendrical days in between)
> (-) (enddate, begindate) =  (alg for # of interest days in between)
> (-) (enddate, begindate) =  (alg for # of work days in between)
>
> Could it be done via multiple dispatch and different return type?
> Or via higher order function, defining subtraction beforehand?
> Or does the "problem" just require different function names?
>
>
>

Reply via email to