Comments (9)
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.
@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.
Hah beat me too it, I had just written the identical code... but yes do that
from accessors.jl.
Thx! I'm really learned a lot from you! ❤️
from accessors.jl.
You need to define your own method of
ConstructionBase.constructorof
forImplication
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, theSVector
could be a type parameter.
Thanks! I'm gonna make it mutable. 😄
from accessors.jl.
Why make it mutable? that's not really a good solution to your problem.
from accessors.jl.
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 Term
s 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.
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.
@AIxer feel free to reopen, if you still have questions.
from accessors.jl.
Related Issues (20)
- "Concat lens": combine multiple lenses side by side HOT 7
- Assemble an object from optics HOT 7
- `hasproperty()` analogue for optics HOT 3
- IndexLens and changing the container size HOT 3
- `Base.show` ambiguity
- @reset naming convention HOT 4
- fate of insert and delete after these functions get into Base
- How to @reset when the field is known only by its equivalent symbol. HOT 2
- Only a single function argument can be the optic target HOT 3
- [Feature request] Set multiple fields at once HOT 6
- Errors in extensions during precompilation HOT 5
- multi-argument modify HOT 4
- `set` for `StructArray`
- Bad idea, would avoid using this pkg HOT 14
- To be or not to be HOT 3
- Traversal order of `Recursive` HOT 11
- `==` not defined for `IndexLens` HOT 4
- String properties not supported HOT 3
- Tests fail on 1.11 HOT 2
- `@(re)set` very slow when a parametric inner constructor is defined? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from accessors.jl.