Stream: beginners

Topic: could you help?


view this post on Zulip Artur Swiderski (Feb 13 2024 at 18:21):

hi I am writing few functions to operate on matrices here https://github.com/salarii/roc_play/blob/main/Matrix.roc . It seems I need two "configurations" to cope with complex and Frac separately(btw. in some languages there would be one "configuration" and implementation for all of them but I can't figure out how to do this in Roc).
It is very disheartening that apparently I can't create one instance of "configuration" and provide it directly inside of every function as needed. Apparently I need to copy paste the same thing over and over. I am talking "opFrec" and "opComplex" which I consider the configurations here

view this post on Zulip Anton (Feb 13 2024 at 18:46):

Hi Artur :)
This seems like something suited for Abilities.
See this example to learn how to implement your own Ability.

view this post on Zulip Artur Swiderski (Feb 13 2024 at 20:54):

thx Anton, it looks like I could try this, but anyway why I have to repeat opComplex or opFrec every time. Seems to me like a bug

view this post on Zulip Brendan Hansknecht (Feb 13 2024 at 22:05):

Not sure if this is the issue or not, but this type looks incorrect:

opFrec : OperationType (Frac a)

Shouldn't it be:

opFrec a : OperationType (Frac a)

Same with the complex ops.

view this post on Zulip Brendan Hansknecht (Feb 13 2024 at 22:05):

Also yeah, what you are trying to do definitely should work.

view this post on Zulip Artur Swiderski (Feb 14 2024 at 12:47):

@Brendan Hansknecht you overlooked that those guys are not types, they are instances of something. Anyway when I try to assign them to "op" directly there are compilation errors. Anyway when I will have more time I will try abilities

view this post on Zulip Brendan Hansknecht (Feb 14 2024 at 17:22):

Ah, yeah.

view this post on Zulip Brendan Hansknecht (Feb 14 2024 at 17:25):

So I think this is a unification bug. Given the types print out as identical, I assume this is equivalent to #beginners > Puzzling type error

view this post on Zulip Brendan Hansknecht (Feb 14 2024 at 17:25):

A workaround is to make opComplex and opFreq lazily generated

view this post on Zulip Brendan Hansknecht (Feb 14 2024 at 17:26):

Might also need to comment out the type

view this post on Zulip Brendan Hansknecht (Feb 14 2024 at 17:26):

So change the definition to opComplex = \{} -> ...


Last updated: Jul 06 2025 at 12:14 UTC