You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
julia>∘(sin, cos, tan)
sin ∘ cos ∘ tan
julia>∘(sin, cos)
sin ∘ cos
julia>∘(sin,)
sin (generic function with 14 methods)
julia>∘()
ERROR: MethodError: no method matching ∘()
whereas it should arguably return Base.identity.
Similarly, reduce_empty(∘) should return Base.identity so that empty reductions work:
julia>foldl(∘, (sin, cos, tan))
sin ∘ cos ∘ tan
julia>foldl(∘, (sin, cos))
sin ∘ cos
julia>foldl(∘, (sin,))
sin (generic function with 14 methods)
julia>foldl(∘, ())
ERROR: MethodError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer
Stacktrace:
[1] reduce_empty(op::Base.BottomRF{typeof(∘)}, ::Type{Union{}})
@ Base ./reduce.jl:360
Update: The 1-arg method was added in #34251, and I see that at this point the possibility for a zero-argument version ∘() = identity was explicitly proposed, and rejected on the grounds that ∘ might be applicable to more than just Functions, in which case the identity element becomes ambiguous:
That's based on the desire to have ∘ for other "morphisms" than functions, which has been requested before, e.g. in the discussion where compose was requested as an ASCII name for ∘.
The text was updated successfully, but these errors were encountered:
stevengj
added
bug
Indicates an unexpected problem or unintended behavior
and removed
bug
Indicates an unexpected problem or unintended behavior
labels
Jan 9, 2024
Currently,
∘()
gives aMethodError
:whereas it should arguably return
Base.identity
.Similarly,
reduce_empty(∘)
should returnBase.identity
so that empty reductions work:Update: The 1-arg method was added in #34251, and I see that at this point the possibility for a zero-argument version
∘() = identity
was explicitly proposed, and rejected on the grounds that∘
might be applicable to more than justFunction
s, in which case the identity element becomes ambiguous:The text was updated successfully, but these errors were encountered: