Create constructor for type without a default constructor

What you are returning there is a closure. I am not sure what you mean by “constructor for these types”?

You can also define a struct and derive it from Function, this way you can explicitly define the closure and other methods:

julia> struct Model <: Function
           a
           b
       end

julia> (m::Model)(x) = m.a * x + m.b

julia> mymodel = Model(4, 2)
(::Model) (generic function with 1 method)

julia> mymodel(5)
22

julia> methods(Model)
# 1 method for type constructor:
[1] Model(a, b) in Main at REPL[5]:2
3 Likes