On Wednesday, April 30, 2014 3:20:23 PM UTC+1, Tim Holy wrote:
>
> You can add this as the first line of your function:
> assert_leaftype(T)
> where
> assert_leaftype(T) = isleaftype(T) || error("Must be a concrete type")
>
> To your users, this is at least as useful as
> ERROR: no method myfunction(Array{Real,1})
> which is what it would be if you relied on method dispatch to generate the
> error (which is what I think you're asking for).
>
> --Tim
>
It's OK, but it still requires me to have a static parameter. Is there a
O(1) time solution which avoids the need for static parameters. Something
like:
function frob(x::Array)
isleaftype(x) || error("Homogeneous array required")
though I know this won't work.