On Wednesday, April 30, 2014 8:16:40 AM UTC-5, Oliver Woodford wrote: > > On Wednesday, April 30, 2014 2:09:45 PM UTC+1, Patrick O'Leary wrote: >> >> On Wednesday, April 30, 2014 7:52:16 AM UTC-5, Oliver Woodford wrote: >>> >>> Is that correct? If not, what really is the correct way to constrain >>> input arrays to be homogenous? >>> >> >> The tendency in Julia is to embrace that it's a dynamic language, and not >> excessively type constrain inputs. While I don't think there's a way to do >> exactly what you want, why do you want to do it? >> >> > When my function will be a lot slower if you pass in a heterogeneous > array, and I want to avoid programmers accidentally and obliviously doing > that. Now, I could convert heterogeneous arrays to homogeneous ones within > the function, but the Julia style > guide<http://julia.readthedocs.org/en/latest/manual/style-guide/#handle-excess-argument-diversity-in-the-caller>very > sensibly counsels against that. >
It's a flexible type system, but it doesn't provide the power of ML or Haskell. If you really, really want this, do a runtime check: reduce((==), [typeof(el) for el in a])