# Placement of \`do\` in choices

**URL:** <https://forum.canton.network/t/placement-of-do-in-choices/1720>\
**Category:** App Development\
**Tags:** daml\
**Created:** [December 1, 2020, 9:49am UTC](https://forum.canton.network/t/placement-of-do-in-choices/1720 "2020-12-01T09:49:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [December 1, 2020, 9:49am UTC](https://forum.canton.network/t/placement-of-do-in-choices/1720/1 "2020-12-01T09:49:59Z")

</div>

I find it very confusing that for choices the placement of the `do` token is handled differently for `controller` first vs `choice` first syntax.

With `controller` first, you can leave the `do` block at the end of the statement, like so:

```haskell
    controller counterparty can
      Sell : ContractId FinancialContract with obligations: Obligations do
        ...

```

But with choice first, this doesn’t compile:

```haskell
    choice EnterInto : ContractId MasterAgreement with requestor : Party
      controller requestor do 
        create MasterAgreement with bearer = requestor, counterparty

```

But moving the `do` one line down does:

```haskell
    choice EnterInto : ContractId MasterAgreement with requestor : Party
      controller requestor
        do create MasterAgreement with bearer = requestor, counterparty

```

Is this intentional? Why this difference?

---

<div class="post-metadata">

**Author:** ![Nick\_Chapman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nick_chapman/32/777_2.png) [@Nick\_Chapman](https://forum.canton.network/u/Nick_Chapman)\
**Post date:** [December 1, 2020, 11:31am UTC](https://forum.canton.network/t/placement-of-do-in-choices/1720/2 "2020-12-01T11:31:56Z")

</div>

Yes, this is somewhat unfortunate.

The difference stems from the fact that the older `controller`-first syntax includes the `can` keyword, which allows the parser to know when the list of controller-parties is finished – because in general there can be multiple controller parties:

```
controller counterparty1, counterparty2 can
  Sell : ContractId FinancialContract with obligations: Obligations do
     ...

```

The layout rules of DAML then insert implicit braces to make the party-list explicit. These braces can be provided explicitly if you like, making the following parse valid:

```
controller { counterparty1, counterparty2 } can
  Sell : ContractId FinancialContract with obligations: Obligations do
     ...

```

However, in the newer `choice`-first syntax, there is no `can` keyword to mark the end of the controller-parties. So the end of the party list (even a singleton list) must be marked either with a line break (allowing layout to do it’s stuff):

```
choice EnterInto : ContractId MasterAgreement with requestor : Party
  controller requestor
    do create MasterAgreement with bearer = requestor, counterparty

```

Or, again, explicit braces may be inserted. Which allows the entire controller declaration on a single line:

```
choice EnterInto : ContractId MasterAgreement with requestor : Party
  controller { requestor } do create MasterAgreement with bearer = requestor, counterparty

```

Or, split after the `do`, if you prefer:

```
choice EnterInto : ContractId MasterAgreement with requestor : Party
  controller { requestor } do
    create MasterAgreement with bearer = requestor, counterparty
```

---

<div class="post-metadata">

**Author:** ![Luciano](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/luciano/32/319_2.png) [@Luciano](https://forum.canton.network/u/Luciano)\
**Post date:** [December 1, 2020, 12:30pm UTC](https://forum.canton.network/t/placement-of-do-in-choices/1720/3 "2020-12-01T12:30:12Z")

</div>

would this also be solved by allowing a `can` in the choice-first syntax?

---

<div class="post-metadata">

**Author:** ![Nick\_Chapman](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/nick_chapman/32/777_2.png) [@Nick\_Chapman](https://forum.canton.network/u/Nick_Chapman)\
**Post date:** [December 1, 2020, 3:58pm UTC](https://forum.canton.network/t/placement-of-do-in-choices/1720/4 "2020-12-01T15:58:27Z")

</div>

It’s possible having a keyword at this point would also get you the layout you want, without explicit braces. However there are problems with using `can` because it has the wrong layout behaviour as a consequence of the old `controller`-first syntax.

In the old syntax, `can` is is followed by a list of Choice declarations, in braces, explicit or implicit. In the new syntax, `can` would be followed by the choice-body expression, which does not have braces.

---

<div class="post-metadata">

**Author:** ![Levente\_Barczy](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/levente_barczy/32/544_2.png) [@Levente\_Barczy](https://forum.canton.network/u/Levente_Barczy)\
**Post date:** [December 11, 2020, 8:11pm UTC](https://forum.canton.network/t/placement-of-do-in-choices/1720/5 "2020-12-11T20:11:26Z")

</div>

Hi, for that very reason, I put the `do` on the next line in a `choice` choice. Also note the double indented `with`:

```haskell
choice MyChoiceName: ContractId SomeTemplate
    with
      arg1: Foo
      party: Party 
  controller party 
    do 
      theThings...

```

Note that this way, the `do` blocks line up exactly between the two choices syntaxes.

> [@Luciano](#):
>
> ```haskell
> choice EnterInto : ContractId MasterAgreement with requestor : Party
> controller requestor do 
> create MasterAgreement with bearer = requestor, counterparty
> 
> ```
