朱莉娅(Julia)的OOP替代品
我正在尝试学习一些朱莉娅,所以我正在写一些语言的小项目。
我想在朱莉娅(Julia)中写一个简单的感知者,但它不是面向对象的,所以我不能创建类perceptron,例如在python中,
可以在python中编写代码的替代方法是什么?我看到有结构,但这看起来像C结构,所以我想知道是否有更强大的方法。
I'm trying to learn a bit of Julia, so i'm writing some small projects in the language.
I'd like to write, for example, a simple Perceptron in Julia, but it is not object oriented, so i can't create a class Perceptron, like in python
What is a possible alternative to write a code like in Python? I saw that there are structures, but this looks like C structure, so I was wondering if there is a more powerful way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的“更强大的方式”是类型层次结构系统: https:// /docs.julialang.org/en/v1/manual/types/
在朱莉娅(Julia Supertype必须是
抽象类型
,也有参数化类型的子类型,但是它们不是用<:
>)子类型保留父母的方法专业化,除非您更改其定义。
朱莉娅(Julia)亚型对抽象类型的影响之一是孩子们不继承父母领域(因为他们没有一个)。
The "more powerful way" you're seeking is the type hierarchy system: https://docs.julialang.org/en/v1/manual/types/
In julia, despite not being OOP, you can still subtypes other types with
<:
when making its definition (but the supertype must be anabstract type
, there are subtypes of parametrized type too, but they aren't made with<:
)The subtypes keep the method specialisation of their parents, unless you change their definition.
One of the effect of Julia subtyping on abstract types is that childs don't inherit of parents fields (as they just don't have one).