-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Figured out complicated parametric subtyping of functors, functions, …
…and their types
- Loading branch information
Showing
1 changed file
with
21 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
density_profile(::Val{:one}, x::Real; a::Real)::Float64 = x + a | ||
struct DensityProfileFunctionType{MediumSymbol} <: Function end | ||
|
||
struct DensityProfile{F <: Function} | ||
profile::F | ||
const ocean_density_profile = DensityProfileFunctionType{:Ocean}() | ||
|
||
function DensityProfile(model::Val; pars...) | ||
profile(x::Real)::Float64 = density_profile(model, x; pars...) | ||
new{typeof(profile)}(profile) | ||
ocean_density_profile(::Val{:Homogeneous}, z::Real; ρ::Real = 1500.0) = ρ | ||
|
||
const seabed_density_profile = DensityProfileFunctionType{:Seabed}() | ||
|
||
seabed_density_profile(::Val{:Homogeneous}, z::Real; ρ::Real = 3000.0) = ρ | ||
|
||
abstract type OceanographyProfile <: Function end | ||
|
||
struct DensityProfile{MediumSymbol, ProfileFunctionType <: Function} <: OceanographyProfile | ||
profile::ProfileFunctionType | ||
|
||
function DensityProfile{MediumSymbol}(model::Val; pars...) where {MediumSymbol} | ||
profile(z::Real) = ocean_density_profile(model, z; pars...) | ||
return new{MediumSymbol, profile |> typeof}(profile) | ||
end | ||
end | ||
|
||
function (den::DensityProfile{F} where {F <: Function})(x::Real) | ||
den.profile(x)::Float64 | ||
function (den::DensityProfile{MediumSymbol, ProfileFunctionType} where {MediumSymbol, ProfileFunctionType})(z::Real) | ||
den.profile(z) | ||
end | ||
|
||
ocn_den = DensityProfile{:Ocean}(Val(:Homogeneous); ρ = 1520.0) | ||
sbd_den = DensityProfile{:Seabed}(Val(:Homogeneous); ρ = 3200.0) |