1

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.

TheSnow
  • 45
  • 4
  • 1
    Related: https://stackoverflow.com/questions/56257781/how-do-we-do-classes-in-julia – Cameron Bieganek Apr 17 '22 at 22:21
  • You may want to have a look to this implementation: https://sylvaticus.github.io/SPMLJ/dev/03_-_ML1_-_Introduction_to_Machine_Learning/0302_-_The_Perceptron_classifier.html#A-better-organisation – Antonello Apr 18 '22 at 11:35
  • @Antonello I can't open your link, file not found – TheSnow Apr 18 '22 at 12:18
  • It's the Markdown formatting. [Here it is](https://sylvaticus.github.io/SPMLJ/stable/03_-_ML1_-_Introduction_to_Machine_Learning/0302_-_The_Perceptron_classifier.html#A-better-organisation) – Antonello Apr 18 '22 at 14:41

1 Answers1

1

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 an abstract 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).

awnmp
  • 26
  • 1