G-d willing
Hello,
I was wondering why Daml can’t handle same choice names for different templates?
It makes the naming convention of choices to be longer than normal.
Comparing it to OOP, different classes can have same method names…
Thanks,
G-d willing
Hello,
I was wondering why Daml can’t handle same choice names for different templates?
It makes the naming convention of choices to be longer than normal.
Comparing it to OOP, different classes can have same method names…
Thanks,
In general, different templates can have the same choice name. What is not possible is to have different templates with the same choice name within a single module.
The reason for that is that each choice generates a data type of the same name for the choice argument. Daml does not have scoping of data-types beyond the module level so it’s not possible to have two datatypes with the same name declared in the same module.
You could imagine various alternative module/scoping concepts that would allow for this but we inherited this from Haskell which has the same limitation so for now we’re stuck with this.
G-d willing
It could be fixed easily by generating a data type that is combined from the template name and the choice name together.
I understand the limitation, and have to live with this. However, I just wanted to know the reason for it.
So, Haskell is the one to blame on this one
Thanks for your answer
It could be fixed easily by generating a data type that is combined from the template name and the choice name together.
The problem with that is that the datatype is not just an internal implementation detail. It’s the thing you pass when you call exercise
, e.g., exercise X (YourChoice with f = 23)
. If we generated a type with a different name, things would get pretty confusing since that’s also the type that you would have to use here.