|
|
|
|
|
by kelipso
925 days ago
|
|
I think it was more like you have a function over an abstract type like: foo(x::Number) = x+1 And then someone else creates a new type thats a subtype of Number. And they run foo(x) and get errors or unexpected output. Problem is the new type they created doesn't follow the assumptions that foo expects. Throw multiple dispatch into the mix and it gets even harder. |
|
> Problem is the new type they created doesn't follow the assumptions that foo expects.
If you define that function and someone else (i.e. a user of your lib) defines a subtype of Number and calls your function on it, and it fails, then they haven't respected the interface to Number. There's nothing wrong with that function or type specialization in that case. In that case it's all about defining useful interfaces and respecting, as much of programming is.
E.g. if someone defines a subtype of Number because he has something that's kind of like a number in some respects but not others, maybe that shouldn't be an subtype of Number.
You also shouldn't define functions that have obscure conditions for being properly useable - at least if you expect your code to be useful more broadly. Nothing here is specific to Julia though.
If you have other specific examples we could discuss more.