Comments (2)
I see. But I think inheritance can be used
import crypto
schema Obj:
id: str
schema MySchema1(Obj):
id = crypto.uuid()
name: str
schema MySchema2(Obj):
displayName: str
collectIDs = lambda objs: [Obj] {
ret = [v.id for v in objs]
}
res1 = collectIDs([MySchema1 {name = ""}])
res2 = collectIDs([MySchema2 {id = "id", displayName = ""}])
I understand duck types like Go and Typescript, which can be assigned values as long as they have a partial order relationship rather than an explicit declaration. KCL considered this feature at the beginning of its design, but still adopts strict type inheritance and checking for types defined using the schema keyword, because in the schema, besides attributes, other logic can be defined. In addition, KCL also has the protocol keyword, which is a more stringent type of schema that only allows attributes to be defined within it. Perhaps this semantics can be extended.
schema ASchema:
id: str
name: str
protocol ASchemaProtocol:
id: str
a: ASchemaProtocol = ASchema {....}
from kcl.
oh nice, yes this works great, thanks!
from kcl.
Related Issues (20)
- [Enhancement] Enhance highlighting of nested quotes in long strings. HOT 8
- [Enhancement] Do not upgrade type in the assign statement for the literal type
- kcl run split stderr and stdout ? HOT 2
- Have not get the | - + from """ HOT 2
- Have Repeat run the if conditional . HOT 2
- [BUG] Support configurable PROTOC environment variable with fallback to vendored binaries
- The implicit type specification issue (KCL_FAST_EVAL=1) HOT 1
- Conditional checks on imported resources HOT 1
- argocd kcl plugin rendering is slow and file.modpath is cached by different kcl modules HOT 12
- doc generate error / 文档生成错误 HOT 4
- When I use attribute as a literal type, the doc generate error. HOT 2
- [GLCC] Enhancement: KCL IDE automatically updates the dependencies through the mod toolchain. HOT 4
- [Enhancement] Enhance the completion experience of KCL Import for both internal and external packages
- How to check dict type in schema HOT 2
- Support procedural for loops HOT 3
- [Bug] Wrong completion items for the newline char in the schema context. HOT 1
- How to get object references? (Rust SDK) HOT 1
- How to check the optional attribute HOT 2
- [Bug] Wrong Definition and Completion items in the schema config for the left attribute and right value.
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 kcl.