Ok sorry, dist::Sampleable actually works...

Le vendredi 13 novembre 2015 17:11:53 UTC+1, [email protected] a écrit :
>
> Hello,
>
> I want to write a function sample(d, n) where n is a number of samples and 
> d is a distribution from the package Distributions.
> I would like to ensure that what is given as d in the function is indeed a 
> distribution, ideally I'd like to write something like 
> sample(d::Distribution, n::Int).
> A normal distribution d = Normal(0.0, 1.0) is of type 
> Distributions.Normal, and a uniform distribution d = Uniform(0.0, 1.0) is 
> of type Distributions.Uniform.
> So I don't think I have a way to specify the type of d inside the 
> signature of sample.
> All that I know is that the type of these distributions are subtypes of 
> Sampleable.
> So for now I'm stuck with:
>
> function sample(d, n::Int)
>     assert(typeof(d) <: Sampleable)
>     ...
> end
>
> But maybe there is another way to say that d should derive from a specific 
> type..? (Inside the function signature ideally.)
>
> Thank you,
>

Reply via email to