See also 
https://groups.google.com/forum/#!searchin/julia-users/invariance$20covariance$20contravariance
 
for discussions of different possibilities for handling inheritance with 
typed parameters. I was convinced by Stefan's arguments there that Julia's 
invariance is the least bad strategy.

On Sunday, May 25, 2014 4:32:42 PM UTC-7, Adam Smith wrote:
>
> I agree to be as generic as possible. I should have used this second 
> example instead, a quite common scenario where being generic doesn't make 
> as much sense:
>
> function output(context::Context, strings::Vector{String})
>     context.something()
>     # Call the single-string version of the function on each item
>     for string in strings output(string) end
> end
>
> output(context, ["Hi there"])
>
> I have already encountered this pattern a number of times in just my few 
> weeks with Julia; wrapping a function with a version that takes a single 
> item with one that takes a collection of them.
>

At the risk of being annoying by criticizing a purposely simplified 
example, I think you should be careful about over-applying this pattern. As 
you point out, using the same method for containers and values gets you 
into sticky type territory, and Julia already provides lots of convenient 
ways for users to apply a method over a collection.

The convenience you're trying to provide might not always outweigh the 
tradeoffs.

Reply via email to