Why do we need a "for" clause in an interface instance declaration?
- Leonid_RozenbergOP
An interface instance clause
interface instance MyInterface for NameOfTemplate wherecan only occur inside of a
templatedefinition, and it can only refer to the same template. It seems redundant, or do you envision lifting the second restriction? - Gary_Verhaegen 1
module Main where template T with s: Party where signatory s data View = View { a : Int } deriving (Show, Eq) interface I where viewtype View interface instance I for T where view = View 0 - Leonid_Rozenberg
Sure but for the instances inside a template, it is redundant?
- Gary_Verhaegen
I think the point is that the syntax as it exists right now is independent of whether it’s in a template or an interface.
That means you can move it around easily while refactoring, and you don’t have to learn two different syntaxes for the same thing.
That’s clearly not the only way to do it, and interfaces are still in preview so there’s time to change them to some extent I think, but I personally like that “location independence” property.
- Gary_Verhaegen
(Note that by the same argument the interface name is also redundant when the block appears within an interface.)
- cocreature
Gary is right, the syntax was chosen such that we can use the the same syntax regardless of whether it is in an interface or a template and in return we accepted some redundancy.
- Leonid_Rozenberg
Ok, cool, that’s sensible.
I guess I would have preferred a shorter version of
interface instance [I|T]...to keep things terse, but I could understand how it complicates things downstream.
- Leonid_Rozenberg
Thinking about this
Gary_Verhaegen:That means you can move it around easily while refactoring, and you don’t have to learn two different syntaxes for the same thing.
a little bit more. I think this cuts both ways. In a large code base you would want to have the ability to quickly search for the difference.
To support both approaches, what if we make the redundant parts optional? So that in an
templateI can writeinterface instance MyInterface whereand in an
interfaceI can writeinterface for MyTemplate where?