function frob(x::Array)
isleaftype(eltype(x)) || error("Homogeneous array required')?

Though, IMO, this is all a non-issue in my experience. Just specifying
frob{T<:Real}(x::Vector{T}) gets you exactly what you want--the ability to
have JIT generate fast, efficient code for a range of types that the user
can specify. The fact that this has never come up before or in any package
implementations, to me, indicates that this issue if more of getting used
to idiomatic Julia and spending some time playing with parametric types and
the interactions with the type hierarchy.

I come from a non-technical background and at first, the idea of parametric
functions/types was a little wild and hard to wrap my head around, but
after reading through the manual several times (which has a lot of great
stuff!) and developing my own non-trivial codebase (Datetime.jl), I feel
I'm comfortable with use cases and how they work in general. I think if you
spend some more time developing code, poking around popular packages and
Base, you'll come to find that there isn't really anything broken here
(though quite possibly some things that need cleaned up a little).

Cheers,

-Jacob


On Wed, Apr 30, 2014 at 10:37 AM, Oliver Woodford <oliver.woodf...@gmail.com
> wrote:

> 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.
>

Reply via email to