Skip to content

Monadic iteration for measures? #55

@oschulz

Description

@oschulz

By defining

Base.iterate(m::AbstractMeasure) = rand(m), nothing
Base.iterate(m::AbstractMeasure, ::Nothing) = rand(m), nothing
Base.Iterators.IteratorSize(::Type{<:AbstractMeasure}) = Base.IsInfinite()

we could make measures monadic in respect to Julia's iteration interface:

julia> using Base.Iterators, MeasureTheory
julia> take((x^2 for x in Normal()), 10) |> collect
10-element Vector{Float64}:
[...]

This would play well semantically with a syntax f.(μ) for pushforward measures (#54).

x^2 for x in Normal would become semantically equivalent to x ~ Normal(); return x^2 in a model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions