# Daml Syntax Help

**URL:** <https://forum.canton.network/t/daml-syntax-help/4368>\
**Category:** App Development\
**Tags:** daml, damlhub\
**Created:** [April 18, 2022, 11:13pm UTC](https://forum.canton.network/t/daml-syntax-help/4368 "2022-04-18T23:13:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rikotacards](https://avatars.discourse-cdn.com/v4/letter/r/f0a364/32.png) [@rikotacards](https://forum.canton.network/u/rikotacards)\
**Post date:** [April 18, 2022, 11:13pm UTC](https://forum.canton.network/t/daml-syntax-help/4368/1 "2022-04-18T23:13:50Z")

</div>

I have the trigger code below, and I’m wondering if I can write a `do` block inside a filter’s callback function. I’ve written in a comment in the code “NEED HELP HERE”

when trying to build, I get `daml/AcceptSwapTrigger.daml:36:13: error: parse error (possibly incorrect indentation or mismatched brackets)`

But my IDE is acting strange and it’s not giving me any red error squiggles. And I’m not sure what might be causing my IDE to do that. I’ve tried to launch Daml studio, and followed the steps for installing it in PATH, etc, but that wasn’t working either.

```haskell
acceptSwapTrigger: T.Trigger ()
acceptSwapTrigger = T.Trigger 
 { initialize = pure (),
  updateState = \_ -> pure (),
  registeredTemplates = T.RegisteredTemplates [T.registeredTemplate @Asset, T.registeredTemplate @Trade, T.registeredTemplate @AssetHoldingAccount, T.registeredTemplate @TransferPreApproval],
  rule = \p -> do
    tradeRequests <- T.query @Trade
    allAssetContracts <- T.query @Asset

    let isMyIncomingTrades = (\tradeRequests -> tradeRequests.receiver == p)
    let myTrades = filter (\(_, contract) -> isMyIncomingTrades contract) tradeRequests

    debug ("asset holding account invites", myTrades)

    
    unless ( DA.Foldable.null myTrades ) do 
      case myTrades of 
        [] -> pure ()

        (tradeCid, c) :: _ -> do
          let isRequestedAsset = (\asset -> do
             -- NEED HELP HERE, isRequestedAsset is a filter function. 
             -- Can I use "do" here? I want to compare a fetched contract's attribute
            requestedAssetTxPreApproval <- T.queryContractId p c.requestedAssetsTxPreApprovalCid
          
             asset.assetType == requestedAssetTxPreApproval.asset.assetType && asset.owner == p)
          let requestedAssets = filter(\(cid,contract) -> isRequestedAsset contract) allAssetContracts
          debug("REQUESTED ASSETS", requestedAssets)
          let requestedAssetCids = map fst requestedAssets
          T.dedupExercise tradeCid Trade_Settle with 
            requestedAssetCids = requestedAssetCids
    debug $ "TRIGGERED",
  heartbeat = None
}

```

---

<div class="post-metadata">

**Author:** ![cocreature](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/cocreature/32/36_2.png) [@cocreature](https://forum.canton.network/u/cocreature)\
**Post date:** [April 19, 2022, 6:56am UTC](https://forum.canton.network/t/daml-syntax-help/4368/2 "2022-04-19T06:56:14Z")

</div>

You need to indent the body of the let binding further than the let itself so

```haskell
          let isRequestedAsset = (\asset -> do
                -- NEED HELP HERE, isRequestedAsset is a filter function.
                -- Can I use "do" here? I want to compare a fetched contract's attribute
                requestedAssetTxPreApproval <- T.queryContractId p c.requestedAssetsTxPreApprovalCid
                asset.assetType == requestedAssetTxPreApproval.asset.assetType && asset.owner == p)

```

Your next issue is that `queryContractId` does not take a party argument for triggers so drop that:

```haskell
requestedAssetTxPreApproval <- T.queryContractId c.requestedAssetsTxPreApprovalCid

```

Next, your filter function needs to work in `TriggerA` so you need to use `filterA` and `pure` in the filter function.  
Finally, `queryContractId` returns an `Optional` so you need to handle the case where it’s not present. Putting the last two fixes together you get

```haskell
          let isRequestedAsset = (\asset -> do
                -- NEED HELP HERE, isRequestedAsset is a filter function.
                -- Can I use "do" here? I want to compare a fetched contract's attribute
                requestedAssetTxPreApproval <- T.queryContractId c.requestedAssetsTxPreApprovalCid
                pure $ optional False (\preapproval -> asset.assetType == preapproval.asset.assetType && asset.owner == p) requestedAssetTxPreApproval)
          requestedAssets <- filterA (\(cid,contract) -> isRequestedAsset contract) allAssetContracts

```

which compiles fine.

As for why vscode doesn’t show issues, take a look at View → Output → Select daml language server from the drop down and see if there’s anything in there. Also try Ctrl/Cmd-Shift-P → reload window and see if the issue disappears.
