Parameterised contracts #199

Open
opened 2019-12-09 21:36:53 +09:00 by zxq9 · 4 comments
zxq9 commented 2019-12-09 21:36:53 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

To make contract inheritance (#198) more useful it might be nice to support parameterised contracts:

contract Parent(type t, x : t) =
  ...
contract Main is Parent(int, 0) =
  ...
*Created by: UlfNorell* To make contract inheritance (#198) more useful it might be nice to support parameterised contracts: ```sophia contract Parent(type t, x : t) = ... contract Main is Parent(int, 0) = ... ```
zxq9 commented 2019-12-11 08:36:34 +09:00 (Migrated from gitlab.com)

Created by: nikita-fuchs

If it was decided to open the pandorra's box of inheritance, then we should add this, certainly. I like this syntax, but what would the deployment look like ? The parameters I pass during deployment are meant for the inheriting contract's init function. The uncool way to solve this would be something like

contract Parent =
    init(type t, x : t)
  ...
contract Main is Parent =
    init(foo: int, bar: string, t: type, x : t)
        Parent(t, x)
  ...

basically initializing the parants in the children's init functions with data we pass to them during deployment.

*Created by: nikita-fuchs* If it was decided to open the pandorra's box of inheritance, then we should add this, certainly. I like this syntax, but what would the deployment look like ? The parameters I pass during deployment are meant for the inheriting contract's init function. The uncool way to solve this would be something like ``` contract Parent = init(type t, x : t) ... contract Main is Parent = init(foo: int, bar: string, t: type, x : t) Parent(t, x) ... ``` basically initializing the parants in the children's init functions with data we pass to them during deployment.
zxq9 commented 2019-12-11 15:21:16 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

You would not be allowed to deploy a parameterised contract, you'd have to instantiate it first. This could be done by a tool though:

contract MyContract (params) =
  ...
  • User hits deploy and chooses values vs for params
  • Tool inserts
      contract Main is MyContract(vs)
    
    and deploys
*Created by: UlfNorell* You would not be allowed to deploy a parameterised contract, you'd have to instantiate it first. This could be done by a tool though: ```sophia contract MyContract (params) = ... ``` - *User hits deploy and chooses values `vs` for params* - *Tool inserts* ```sophia contract Main is MyContract(vs) ``` *and deploys*
zxq9 commented 2019-12-11 19:26:55 +09:00 (Migrated from gitlab.com)

Created by: radrow

Will arguments for init still make sense when this comes in?

*Created by: radrow* Will arguments for `init` still make sense when this comes in?
zxq9 commented 2019-12-11 19:32:16 +09:00 (Migrated from gitlab.com)

Created by: UlfNorell

Yes

  • init arguments don't require recompiling the contract
  • you can compute parent init arguments from your own init arguments
  • init arguments aren't available everywhere in the contract
*Created by: UlfNorell* Yes - init arguments don't require recompiling the contract - you can compute parent init arguments from your own init arguments - init arguments aren't available everywhere in the contract
Sign in to join this conversation.
No Milestone
No project
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/sophia#199
No description provided.