GithubHelp home page GithubHelp logo

Comments (9)

rafaqz avatar rafaqz commented on June 7, 2024 1

You need to define your own method of ConstructionBase.constructorof for Implication because the parameters are not known from the fields. The problem is it can be difficult to detect which parameters should be kept - consider a much more complicated type with nested parameters.

For these simple types we could possibly detect that O isnt known from the fields, and keep it.

Implication also isnt type-stable by the way, the SVector could be a type parameter.

from accessors.jl.

jw3126 avatar jw3126 commented on June 7, 2024 1

@AIxer if overloading ConstructionBase.constructorof sounds scary to you, it is just a single line:

ConstructionBase.constructorof(::Type{Implication{O}}) where {O} = Implication{O}

from accessors.jl.

rafaqz avatar rafaqz commented on June 7, 2024 1

Hah beat me too it, I had just written the identical code... but yes do that

from accessors.jl.

AIxer avatar AIxer commented on June 7, 2024 1

Thx! I'm really learned a lot from you! ❤️

from accessors.jl.

AIxer avatar AIxer commented on June 7, 2024

You need to define your own method of ConstructionBase.constructorof for Implication because the parameters are not known from the fields. The problem is it can be difficult to detect which parameters should be kept - consider a much more complicated type with nested parameters.

For these simple types we could possibly detect that O isnt known from the fields, and keep it.

Implication also isnt type-stable by the way, the SVector could be a type parameter.

Thanks! I'm gonna make it mutable. 😄

from accessors.jl.

rafaqz avatar rafaqz commented on June 7, 2024

Why make it mutable? that's not really a good solution to your problem.

from accessors.jl.

AIxer avatar AIxer commented on June 7, 2024

In fact, I seldom use immutable struct, but I'd very like to use it, maybe I should learn some Haskell.
I'm rewriting Non-Axiomatic Reasoning System. The term Implication is from its formal language called Narsese. There are may terms in Narsese, such as Inheritance, Similarity, etc. they are types of Term and use Terms as their comps. The whole system never changes its terms in place, but copy then change sometimes (all operation could use immutable methods). emm, the problem is I don't know what's the best structure to represent Term, they are can't type stable. Also, I defined abstract type Term end.
So, just simply:

mutable struct Implication{O <: TemporalOrder} <: Term
    comps::Vector{T} where T <: Term
    octime::UInt
end

struct ExtSet <: Term
    comps::Vector{T} where T <: Term
end

emm, any ideas? And I'm very appreciate your help! @rafaqz @jw3126

from accessors.jl.

rafaqz avatar rafaqz commented on June 7, 2024

Always use type parameters. Vetcor{T} is not type stable. You can include that limitation with the type parameter as in the first example, but I normally wouldn't bother, and just keep it simple as in the second example.

 struct Implication{O <: TemporalOrder,C <: Vector{<:Term}} <: Term
    comps::C
    octime::UInt
end
# This is so `constructorof` will still work
Implication{O}(comps::C, octime) where {O,C} = Implication{O,C}(comps, octime) 

struct ExtSet{C} <: Term
    comps::C
end

from accessors.jl.

jw3126 avatar jw3126 commented on June 7, 2024

@AIxer feel free to reopen, if you still have questions.

from accessors.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.