• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: unable to share a proc between two classes

Resolved: unable to share a proc between two classes

0
By Isaac Tonny on 16/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve unable to share a proc between two classes

Question:

I am playing around with NIM and classes. Ima trying ti have one i it function for two classes, however it seems that this result in the initialization nit to be possible. The code looks like this
The self.all assignment always return error, cannot assign self. This does not change even if the prod is generic or I write var | var. What error am I making? Thanks.

Best Answer:

The following syntax Attribute|Attributes defines a typeclass.
The nim manual states that “type classes are static constraints to be enforced at type instantiations. Type classes are not really types in themselves but are instead a system of providing generic “checks” that ultimately resolve to some singular type. Type classes do not allow for runtime type dynamism, unlike object variants or methods.”
Procedures using typeclasses are implicitly generic.
A call to a generic proc statically instantiates a specialized proc for each unique type. Therefore, you have to conditionally check what type your generic has resolved to at compile time.
Enough word vomit. Here’s example code:
If you checkout the generated c code you’ll see that the instance of the accept proc for the Second type is the only function that has something.uniqueField = 2.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

nim-lang
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How can I copy files using the ansible.builtin.copy module and avoid conflicting file names?

26/03/2023

Resolved: Reshape tensors of unknown shape with tf.function

26/03/2023

Resolved: Use Svelte Component as Slot

26/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.