Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature deprecation: apply(EquationForm(), eos::EquationOfState) returns a function #52

Closed
singularitti opened this issue Nov 20, 2019 · 1 comment
Labels
blog This is a blog of development breaking Introduce breaking changes deprecation wontfix This will not be worked on
Milestone

Comments

@singularitti
Copy link
Member

Is your feature request related to a problem? Please describe.
This is actually not a feature request but a feature deprecation request. In the past, I allow the following syntax:

apply(EnergyForm(), eos::EquationOfState)
apply(PressureForm(), eos::EquationOfState)
apply(BulkModulusForm(), eos::EquationOfState)

and the usage is

julia> using EquationsOfState, EquationsOfState.Collections

julia> f = apply(EnergyForm(), Vinet(1, 2, 3));

julia> map(f, 1:1:10)
10-element Array{Float64,1}:
 0.0
 0.367905230584308
 0.7652477289745814
 1.0516459435179233
 1.2560420090256408
 1.405149833626178
 1.5165867441792136
 1.6017034530570884
 1.6679539823686644
 1.7203642945516917

julia> g = apply(PressureForm(), Vinet(1, 2, 3));

julia> map(g, 1:1:10)
10-element Array{Float64,1}:
  0.0
 -0.45046308428750254
 -0.3384840350043251
 -0.24010297221667418
 -0.17314062272722755
 -0.12795492664586872
 -0.09677154467733216
 -0.07468060255179591
 -0.05864401631176751
 -0.04674768462396211

julia> h = apply(BulkModulusForm(), BirchMurnaghan3rd(1, 2, 3));

julia> map(h, 1:1:10)
10-element Array{Float64,1}:
 2.0
 0.9216086833346415
 0.444903691617472
 0.2540009203153288
 0.16193296566524193
 0.11130584492987289
 0.08076305569984538
 0.06103515625
 0.047609811583958425
 0.03808959181078831

Which basically means:
apply(EquationForm(), eos::EquationOfState) returns a function that takes a volume v as a variable, suitable for mapping onto any array.
This feature is the so-called Currying in functional programming, named after logician Haskell Curry.

Describe the solution you'd like
But I found Julia provides a nice do block, so the above example is equivalent to

julia> map(1:1:10) do v
           apply(EnergyForm(), eos, v)
       end
10-element Array{Float64,1}:
 0.0
 0.367905230584308
 0.7652477289745814
 1.0516459435179235
 1.2560420090256412
 1.405149833626178
 1.5165867441792138
 1.6017034530570884
 1.6679539823686644
 1.7203642945516917

You can tell the results are exactly the same, but here we only use the method apply(EnergyForm(), eos::EquationOfState, v::Real), which is self-explanatory. So even if we deprecate the syntax

apply(EnergyForm(), eos::EquationOfState)
apply(PressureForm(), eos::EquationOfState)
apply(BulkModulusForm(), eos::EquationOfState)

users can still get the same results without writing extra code. The only downside is that the code is 3 lines, compared to the old one-liner.
By now, I want to introduce as little features as possible to make this code minimal and maintainable. Introducing too many features at once may affect future implementation. Users can write Lambda functions

apply(form::EquationForm, eos::EquationOfState) = v -> apply(form, eos, v)

to re-enable this feature if they really want to use it.

Describe alternatives you've considered
There are some packages (Curry.jl, Curry.jl or Currier.jl) implementing Currying, apart from defining Lambda functions by user themselves.

Please be aware that this is a breaking change if you use the above syntax before @searchengineorientprogramming, I will update docs and tests soon.

@singularitti singularitti added breaking Introduce breaking changes deprecation labels Nov 20, 2019
@singularitti singularitti added this to the v2.0.0 milestone Nov 20, 2019
@singularitti
Copy link
Member Author

singularitti commented Nov 20, 2019

This feature has to be kept because It is confusing to write this line into

model = (x, p) -> map(x) do v
    apply(form, E(p...), v)
end

And those tests have to be written as

@test isapprox(
    map(mp153_volumes) do v
        apply(EnergyForm(), fitted_eos, v)
    end,
    mp153_known_energies_vinet;
    atol = 1e-5,
)

which looks ugly.

@singularitti singularitti added the wontfix This will not be worked on label Nov 20, 2019
@singularitti singularitti added the blog This is a blog of development label Jan 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog This is a blog of development breaking Introduce breaking changes deprecation wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant